self.view.backgroundColor = [UIColor whiteColor];
//UIControl 控制類(lèi)
//addTarget:action:forControlEvents
//添加響應(yīng)事件(滿(mǎn)足什么條件下 讓某人調(diào)用某方法)
/********UISegmentedControl 分段控制器**********/
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"消息",@"電話(huà)",@"微信"]];
seg.frame = CGRectMake(100, 100, 200, 40);
[self.view addSubview:seg];
[seg release];
//選中分段下標(biāo)
seg.selectedSegmentIndex = 0;
//背景顏色
//? ? seg.backgroundColor = [UIColor blackColor];
//渲染顏色
seg.tintColor = [UIColor lightGrayColor];
//插入新的分段
//? ? [seg insertSegmentWithImage:@"陌陌" atIndex:2 animated:YES];
//添加響應(yīng)事件(通過(guò)下標(biāo)值的變化觸發(fā)方法)
[seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
// red
self.redV = [[UIView alloc] initWithFrame:CGRectMake(50, 200, 300, 300)];
self.redV.backgroundColor = [UIColor redColor];
[self.view addSubview:self.redV];
[_redV release];
//greenV
self.greenV = [[UIView alloc] initWithFrame:CGRectMake(50, 200, 300, 300)];
self.greenV.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.greenV];
[_greenV release];
/*****UISlider 滑塊控制器 ******************/
UISlider *sl = [[UISlider alloc] initWithFrame:CGRectMake(50, 50, 200, 50)];
sl.backgroundColor = [UIColor yellowColor];
[self.view addSubview:sl];
[sl release];
//顏色設(shè)置
//滑過(guò)距離的顏色(滑塊左)
sl.minimumTrackTintColor = [UIColor blackColor];
//未滑過(guò)距離的顏色(滑塊右)
sl.maximumTrackTintColor = [UIColor redColor];
//滑塊顏色
sl.thumbTintColor = [UIColor greenColor];
//添加響應(yīng)事件
[sl addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
//滑動(dòng)范圍
//最小值
sl.minimumValue = -100;
//最大值
sl.maximumValue = 1000;
//更新滑塊起始點(diǎn)
sl.value = -100;
/************ UIPageControl 頁(yè)碼控制器 ******************/
UIPageControl *pc = [[UIPageControl alloc] initWithFrame:CGRectMake(50, 150, 100, 50)];
pc.backgroundColor = [UIColor blueColor];
[self.view addSubview:pc];
[pc release];
//頁(yè)數(shù)
pc.numberOfPages = 5;
//當(dāng)前頁(yè)
pc.currentPage = 2;
//顏色
//頁(yè)碼顏色
pc.pageIndicatorTintColor = [UIColor redColor];
//當(dāng)前頁(yè)碼顏色
pc.currentPageIndicatorTintColor = [UIColor yellowColor];
//響應(yīng)事件
[pc addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
/************* UISwicth 開(kāi)關(guān) ****************/
UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(250, 150, 150, 50)];
sw.backgroundColor = [UIColor whiteColor];
[self.view addSubview:sw];
[sw release];
//開(kāi)關(guān)屬性
sw.on = YES;
sw.onTintColor = [UIColor redColor];
sw.tintColor = [UIColor blueColor];
sw.thumbTintColor = [UIColor yellowColor];
//響應(yīng)方法
[sw addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
}
#pragma mark - 開(kāi)關(guān)
-(void)switchAction:(UISwitch *)sw{
NSLog(@"%d",sw.on);
if (sw.on) {
NSLog(@"開(kāi)啟");
}else{
NSLog(@"關(guān)閉");
}
}
#pragma mark - 頁(yè)碼控制器
-(void)pageAction:(UIPageControl *)page{
NSLog(@"%ld",page.currentPage);
}
#pragma mark - 滑塊控制器
-(void)sliderAction:(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ù)一:開(kāi)始視圖
//參數(shù)二:結(jié)束視圖
//參數(shù)三:持續(xù)時(shí)間
//參數(shù)四:動(dòng)畫(huà)選項(xiàng)
//參數(shù)五:完成動(dòng)畫(huà)之后調(diào)用的block
[UIView transitionFromView:self.greenV toView:self.redV duration:1 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) {
}];
}
if (seg.selectedSegmentIndex == 1) {
[UIView transitionFromView:self.redV toView:self.greenV duration:1 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) {
}];
}
NSLog(@"%ld",seg.selectedSegmentIndex);
}