UIControl

UIControl控制类

addtarget:action:forControlEvents

添加响应时间(满足什么条件下让某人调用某方法)

UISegmentedControl分段控制器

UISegmentedControl*seg = [[UISegmentedControlalloc]initWithItems:@[@"消息",@"电话",@"微信"]];

seg.frame=CGRectMake(100,100,200,40);

[self.viewaddSubview:seg];

[segrelease];

选中分段下标

seg.selectedSegmentIndex=0;

背景颜色

seg.backgroundColor = [UIColor blackColor];

渲染颜色

seg.tintColor= [UIColorlightGrayColor];

seg.layer.cornerRadius = 15;

seg.clipsToBounds = YES;

插入新的分段

[seg insertSegmentWithTitle:@"默默" atIndex:2 animated:YES];

添加响应事件(通过下标值的变化触发方法)

[segaddTarget:selfaction:@selector(segAction:)forControlEvents:UIControlEventValueChanged];

UISlide滑块控制器

UISlider*sl = [[UISlideralloc]initWithFrame:CGRectMake(50,50,200,50)];

sl.backgroundColor= [UIColoryellowColor];

[self.viewaddSubview:sl];

[slrelease];

颜色设置

划过距离的颜色

sl.minimumTrackTintColor= [UIColorblackColor];

未划过的颜色(滑块右)

sl.maximumTrackTintColor= [UIColorredColor];

滑块颜色

sl.thumbTintColor= [UIColorgrayColor];

添加响应事件

[sladdTarget:selfaction:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged];

滑动范围

最小值

sl.minimumValue= -100;

最大值

sl.maximumValue=1000;

更新滑块起始点

sl.value= -100;

UIPageControl页码控制器

UIPageControl*pc = [[UIPageControlalloc]initWithFrame:CGRectMake(50,150,100,50)];

pc.backgroundColor= [UIColorblackColor];

[self.viewaddSubview:pc];

[pcrelease];

页数

pc.numberOfPages=4;

当前页

pc.currentPage=3;

颜色

pc.pageIndicatorTintColor= [UIColorredColor];

当前页颜色

pc.currentPageIndicatorTintColor= [UIColorgreenColor];

响应事件

[pcaddTarget:selfaction:@selector(pageAction:)forControlEvents:UIControlEventValueChanged];

UISwiTch开关控制器

UISwitch*sw = [[UISwitchalloc]initWithFrame:CGRectMake(250,150,100,50)];

sw.backgroundColor= [UIColorwhiteColor];

[self.viewaddSubview:sw];

[swrelease];

sw.on=YES;

开启时颜色

sw.onTintColor= [UIColorredColor];

关闭时颜色

sw.tintColor= [UIColoryellowColor];

按钮颜色

sw.thumbTintColor= [UIColorblueColor];

响应方法

[swaddTarget:selfaction:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];

你可能感兴趣的:(UIControl)