// 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 insertSegmentWithTitle:@"陌陌" atIndex:2 animated:YES];
//添加響應事件(通過下標值的變化觸發(fā)方法)
[segaddTarget:selfaction:@selector(segAction:)forControlEvents:UIControlEventValueChanged];
// red
self.redV= [[UIViewalloc]initWithFrame:CGRectMake(50,200,300,300)];
self.redV.backgroundColor= [UIColorgreenColor];
[self.viewaddSubview:self.redV];
[_redVrelease];
//yellow
self.yeV= [[UIViewalloc]initWithFrame:CGRectMake(50,200,300,300)];
self.yeV.backgroundColor= [UIColorgreenColor];
[self.viewaddSubview:self.yeV];
[_yeVrelease];
/*******UISlider滑動控制器******/
UISlider*sl = [[UISlideralloc]initWithFrame:CGRectMake(50,50,200,50)];
sl.backgroundColor= [UIColoryellowColor];
[self.viewaddSubview:sl];
[slrelease];
//顏色設置
//滑過距離的顏色
sl.minimumTrackTintColor= [UIColorblackColor];
//未劃過距離的顏色
sl.maximumTrackTintColor= [UIColorredColor];
//滑塊顏色
sl.thumbTintColor= [UIColoryellowColor];
//添加響應事件
[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];
//頁數(shù)
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= [UIColorblackColor];
sw.thumbTintColor= [UIColoryellowColor];
[swaddTarget:selfaction:@selector(swAction:)forControlEvents:UIControlEventValueChanged];
}
#pragma mark -
-(void)swAction:(UISwitch*)swh{
if(swh.on) {
NSLog(@"開");
}else{
NSLog(@"關");
}
}
#pragma mark -頁碼控制器
-(void)pageAction:(UIPageControl*)page{
NSLog(@"%ld",page.currentPage);
}
#pragma mark -滑塊控制器
-(void)sliderAction:(UISlider*)sl{
NSLog(@"%f", sl.value);
}
#pragma mark -分段控制器
- (void)segAction:(UISegmentedControl*)seg{
NSLog(@"%ld", seg.selectedSegmentIndex);
//獲取視圖對象的方式
//1.tag
//2.屬性
if(seg.selectedSegmentIndex==0) {
// transition過度動畫
//參數(shù)1:開始視圖
//參數(shù)2:結束視圖
//參數(shù)3:結束時間
//參數(shù)4:動畫選項
//參數(shù)5:完成動畫之后調用的block
[UIViewtransitionFromView:self.yeVtoView:self.redVduration:1options:UIViewAnimationOptionTransitionFlipFromLeftcompletion:^(BOOLfinished) {
}];
}
if(seg.selectedSegmentIndex==1) {
[UIViewtransitionFromView:self.redVtoView:self.yeVduration:1options:UIViewAnimationOptionTransitionFlipFromLeftcompletion:^(BOOLfinished) {
}];
}
}