UIControl 控制類
addTarget:forcontrolEvents:添加響應(yīng)事件(滿足什么條件下 讓某人調(diào)用什么方法)
UISegegmentedControl(分段控制器)
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"消息",@"電話",@"微信"]];
seg.frame=CGRectMake(100,50,200,40);
[self.viewaddSubview:seg];
[segrelease];
選中分段下標(biāo)
seg.selectedSegmentIndex=0;//(從0開(kāi)始)
背景顏色
seg.backgroundColor = [UIColor blackColor];
渲染顏色
seg.tintColor= [UIColorlightGrayColor];
插入新的分段
[seg insertSegmentWithTitle:@"陌陌" atIndex:2 animated:YES];
添加響應(yīng)事件(通過(guò)下標(biāo)值得變化觸發(fā)方法)
[segaddTarget:selfaction:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
兩個(gè)頁(yè)面
self.redView= [[UIViewalloc]initWithFrame:CGRectMake(40,160,250,250)];
self.redView.backgroundColor=[UIColorredColor];
[self.viewaddSubview:self.redView];
[_redViewrelease];
green
self.greenView= [[UIViewalloc]initWithFrame:CGRectMake(40,160,250,250)];
self.greenView.backgroundColor=[UIColoryellowColor];
[self.viewaddSubview:self.greenView];
[_greenViewrelease];
/******** UISilder滑塊控制器*********/
UISlider*sl = [[UISlideralloc]initWithFrame:CGRectMake(50,420,250,50)];
sl.backgroundColor= [UIColororangeColor];
[self.viewaddSubview:sl];
[slrelease];
顏色設(shè)置
劃過(guò)距離的顏色
sl.minimumTrackTintColor= [UIColorcyanColor];
為劃過(guò)距離的顏色(滑塊右)
sl.maximumTrackTintColor= [UIColorblueColor];
滑塊顏色
sl.thumbTintColor= [UIColorlightGrayColor];
添加響應(yīng)事件
[sladdTarget:selfaction:@selector(slideAction:) forControlEvents:UIControlEventValueChanged];
滑動(dòng)范圍
最小值
sl.minimumValue= -100;
最大值
sl.maximumValue=1000;
更新滑塊起始點(diǎn)
sl.value= -100;
/************ UIPageControl頁(yè)碼控制器************/
UIPageControl*pc = [[UIPageControlalloc]initWithFrame:CGRectMake(50,100,100,50)];
pc.backgroundColor= [UIColorblackColor];
[self.viewaddSubview:pc];
[pcrelease];
//頁(yè)數(shù)
pc.numberOfPages=4;
//當(dāng)前頁(yè)
pc.currentPage=3;
//顏色(小點(diǎn))
pc.pageIndicatorTintColor= [UIColorredColor];
//當(dāng)前頁(yè)顏色
pc.currentPageIndicatorTintColor= [UIColoryellowColor];
//響應(yīng)事件
[pcaddTarget:selfaction:@selector(pageAction:)forControlEvents:UIControlEventValueChanged];
/************ UISwitch開(kāi)關(guān)控制器************/
UISwitch*sw = [[UISwitchalloc]initWithFrame:CGRectMake(200,110,100,50)];
sw.backgroundColor= [UIColorwhiteColor];
[self.viewaddSubview:sw];
[swrelease];
//開(kāi)關(guān)屬性
sw.on=YES;
//開(kāi)啟時(shí)顏色
sw.onTintColor= [UIColorlightGrayColor];
//關(guān)閉時(shí)顏色
sw.tintColor= [UIColorcyanColor];
//按鈕顏色
sw.thumbTintColor= [UIColorbrownColor];
//響應(yīng)方法
[swaddTarget:selfaction:@selector(swAction:) forControlEvents:UIControlEventValueChanged];
}
#pragma mark -開(kāi)關(guān)控制器
-(void)swAction:(UISwitch*)sw{
if(sw.on) {
NSLog(@"開(kāi)啟");
}else{
NSLog(@"關(guān)閉");
}
}
#pragma mark -頁(yè)碼控制器
-(void)pageAction:(UIPageControl*)page{
NSLog(@"%ld",page.currentPage);
}
#pragma mark -滑塊控制器
-(void)slideAction:(UISlider*)sl{
NSLog(@"%f",sl.value);
}
#pragma mark =分段控制器
-(void)segAction:(UISegmentedControl *)seg{
獲取視圖對(duì)象的方式
1.tag值
2.屬性
if(seg.selectedSegmentIndex==0) {
transition過(guò)渡動(dòng)畫(huà)
參數(shù)1:開(kāi)始視圖
參數(shù)2:結(jié)束視圖
//參數(shù)3:持續(xù)時(shí)間
//參數(shù)4:動(dòng)畫(huà)選項(xiàng)
//參數(shù)5:完成動(dòng)畫(huà)之后調(diào)用的block
[UIViewtransitionFromView:self.greenViewtoView:self.redViewduration:1options:UIViewAnimationOptionTransitionCurlDowncompletion:^(BOOLfinished) {
}];
}
if(seg.selectedSegmentIndex==1) {
[UIViewtransitionFromView:self.redViewtoView:self.greenViewduration:1options:UIViewAnimationOptionTransitionCurlUpcompletion:^(BOOLfinished) {
}];
}
NSLog(@"%ld",seg.selectedSegmentIndex);
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
Dispose of any resources that can be recreated.
}