UI1_UISlider与UISegment

//
//  ViewController.m
//  UI1_UISlider与UISegment
//
//  Created by zhangxueming on 15/7/7.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 100, self.view.frame.size.width-100, 100)];
    slider.backgroundColor = [UIColor cyanColor];

    //设置value 最小值 (保证最大值大于最小值 滑块才能移动)
    slider.minimumValue = 100;
    //设置value 最大值
    slider.maximumValue = 110;
    //设置最大值最小值一端的图片
    slider.maximumValueImage = [UIImage imageNamed:@"truckmax"];
    slider.minimumValueImage = [UIImage imageNamed:@"truckmin"];

    //设置滑块的颜色
    slider.thumbTintColor = [UIColor redColor];
    //设置最小值轨道颜色
    slider.minimumTrackTintColor = [UIColor blackColor];
    //设置最大值轨道颜色
    slider.maximumTrackTintColor = [UIColor greenColor];

    //设置滑块的图片
    [slider setThumbImage:[UIImage imageNamed:@"001.png"] forState:UIControlStateHighlighted];
    [slider setMinimumTrackImage:[UIImage imageNamed:@"002.png"] forState:UIControlStateNormal];
    [slider setMaximumTrackImage:[UIImage imageNamed:@"005.png"] forState:UIControlStateNormal];

    [slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:slider];

    //分段选取器
    NSArray *titles = @[@"百度",@"音乐",@"贴吧",@"图片"];
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:titles];
    segment.frame = CGRectMake(10, 300, self.view.frame.size.width-20, 50);
    segment.selectedSegmentIndex = 1;

    [segment addTarget:self action:@selector(segmentSelectedValueChange:) forControlEvents:UIControlEventValueChanged];
    //增加分段
    [segment insertSegmentWithTitle:@"地图" atIndex:1 animated:YES];

    [self.view addSubview:segment];
}

- (void)sliderValueChange:(UISlider *)slider
{
    //默认value值0.0~1.0
    NSLog(@"value = %.2f", slider.value);
}

- (void)segmentSelectedValueChange:(UISegmentedControl *)segment
{
    NSLog(@"selectedValue = %li", segment.selectedSegmentIndex);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
时间: 2024-12-16 07:02:25

UI1_UISlider与UISegment的相关文章

UISegment属性和使用方法

UISegment属性 1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlStyle) { UISegmentedControlStylePlain,     // large plain 系统默认平板样式 segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; UISegmentedCont

IOS开发UI基础UISegment属性

UISegment属性 1.segmentedControlStyle设置segment的显示样式.typedef NS_ENUM(NSInteger, UISegmentedControlStyle) {UISegmentedControlStylePlain,     // large plain 系统默认平板样式segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; UISegmentedControlS

UISegment

一.每个segment都能被点击,相当于集成了若干个button. 二.常用API 1, initWithItems: //UISegmentedControl独有的初始化?法,?来创建多个分段 2,setTitle: forSegmentAtIndex: //为指定下标的分段设置title 3,selectedSegmentAtIndex //(property)被选中的segment 4,tintColor //(property)segmentedControl条的颜?(含每个segmen

UISegment属性

1.segmentedControlStyle 设置segment的显示样式. 1 typedef NS_ENUM(NSInteger, UISegmentedControlStyle) 2 { 3 UISegmentedControlStylePlain, // large plain 系统默认平板样式 4 //segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; 5 6 UISegmentedContro

简述UISegment的属性和用法

1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlStyle) { UISegmentedControlStylePlain,     // large plain 系统默认平板样式 segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; UISegmentedControlStyleBord

UI开发----UIController及其子类

//  Created By 郭仔    2015年04月17日23:30:33 今天搞了一晚上的设计模式,本来用ios启动流程的初始代理UIApplicationDeleg来设置页面转换的,却越来越麻烦,还是用了简单的笨方法实现了,明天把这个内容写下来. ================== 没什么时间了,直接上代码: ================== UIImageView: // =================UIImageView=========================

iOS开发基础知识--碎片2

iOS开发基础知识--碎片2 六:获得另一个控件器,并实现跳转 UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *registerViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"registerView

iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译

编号 iOS-Apple苹果官方文档翻译名称 博文链接地址 1 苹果API常用英语名词---iOS-Apple苹果官方文档翻译 http://www.cnblogs.com/ChenYilong/p/3495625.html 2 基本控件文档-UIWebView---iOS-Apple苹果官方文档翻译 http://www.cnblogs.com/ChenYilong/p/3556301.html 3 基本控件文档-UITextField属性---iOS-Apple苹果官方文档翻译 http:/

(转)AutoLayout深入浅出三[相遇Scrollview]

原文地址:http://grayluo.github.io/WeiFocusIo/autolayout/2015/01/27/autolayout3/ AutoLayout 与 UIScrollView的相遇是一个不可避免的场景,像UITableView.UIWebView这些都是继承于UIScrollView的,关于它们的autolayout布局大体一致,但还是会有略微不同,而我们这篇讨论的主要是其contentSize问题,所以就直接讲UIScrollView就OK了. 如上图,我们将vie