UIControl控制類
addtarget:action:forControlEvents
添加響應(yīng)時(shí)間(滿足什么條件下讓某人調(diào)用某方法)
UISegmentedControl分段控制器
UISegmentedControl*seg = [[UISegmentedControlalloc]initWithItems:@[@"消息",@"電話",@"微信"]];
seg.frame=CGRectMake(100,100,200,40);
[self.viewaddSubview:seg];
[segrelease];
選中分段下標(biāo)
seg.selectedSegmentIndex=0;
背景顏色
seg.backgroundColor = [UIColor blackColor];
渲染顏色
seg.tintColor= [UIColorlightGrayColor];
seg.layer.cornerRadius = 15;
seg.clipsToBounds = YES;
插入新的分段
[seg insertSegmentWithTitle:@"默默" atIndex:2 animated:YES];
添加響應(yīng)事件(通過下標(biāo)值的變化觸發(fā)方法)
[segaddTarget:selfaction:@selector(segAction:)forControlEvents:UIControlEventValueChanged];
UISlide滑塊控制器
UISlider*sl = [[UISlideralloc]initWithFrame:CGRectMake(50,50,200,50)];
sl.backgroundColor= [UIColoryellowColor];
[self.viewaddSubview:sl];
[slrelease];
顏色設(shè)置
劃過距離的顏色
sl.minimumTrackTintColor= [UIColorblackColor];
未劃過的顏色(滑塊右)
sl.maximumTrackTintColor= [UIColorredColor];
滑塊顏色
sl.thumbTintColor= [UIColorgrayColor];
添加響應(yīng)事件
[sladdTarget:selfaction:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged];
滑動(dòng)范圍
最小值
sl.minimumValue= -100;
最大值
sl.maximumValue=1000;
更新滑塊起始點(diǎn)
sl.value= -100;
UIPageControl頁碼控制器
UIPageControl*pc = [[UIPageControlalloc]initWithFrame:CGRectMake(50,150,100,50)];
pc.backgroundColor= [UIColorblackColor];
[self.viewaddSubview:pc];
[pcrelease];
頁數(shù)
pc.numberOfPages=4;
當(dāng)前頁
pc.currentPage=3;
顏色
pc.pageIndicatorTintColor= [UIColorredColor];
當(dāng)前頁顏色
pc.currentPageIndicatorTintColor= [UIColorgreenColor];
響應(yīng)事件
[pcaddTarget:selfaction:@selector(pageAction:)forControlEvents:UIControlEventValueChanged];
UISwiTch開關(guān)控制器
UISwitch*sw = [[UISwitchalloc]initWithFrame:CGRectMake(250,150,100,50)];
sw.backgroundColor= [UIColorwhiteColor];
[self.viewaddSubview:sw];
[swrelease];
sw.on=YES;
開啟時(shí)顏色
sw.onTintColor= [UIColorredColor];
關(guān)閉時(shí)顏色
sw.tintColor= [UIColoryellowColor];
按鈕顏色
sw.thumbTintColor= [UIColorblueColor];
響應(yīng)方法
[swaddTarget:selfaction:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];