self.view.backgroundColor = [UIColor whiteColor];
//UIControl 控制類
//addTarget:action:forControlEvents
//添加響應事件(滿足什么條件下 讓某人調用某方法)
/********UISegmentedControl 分段控制器**********/
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"消息",@"電話",@"微信"]];
seg.frame = CGRectMake(100, 100, 200, 40);
[self.view addSubview:seg];
[seg release];
//選中分段下標
seg.selectedSegmentIndex = 0;
//背景顏色
//? ? seg.backgroundColor = [UIColor blackColor];
//渲染顏色
seg.tintColor = [UIColor lightGrayColor];
//插入新的分段
//? ? [seg insertSegmentWithImage:@"陌陌" atIndex:2 animated:YES];
//添加響應事件(通過下標值的變化觸發方法)
[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];
//顏色設置
//滑過距離的顏色(滑塊左)
sl.minimumTrackTintColor = [UIColor blackColor];
//未滑過距離的顏色(滑塊右)
sl.maximumTrackTintColor = [UIColor redColor];
//滑塊顏色
sl.thumbTintColor = [UIColor greenColor];
//添加響應事件
[sl addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
//滑動范圍
//最小值
sl.minimumValue = -100;
//最大值
sl.maximumValue = 1000;
//更新滑塊起始點
sl.value = -100;
/************ UIPageControl 頁碼控制器 ******************/
UIPageControl *pc = [[UIPageControl alloc] initWithFrame:CGRectMake(50, 150, 100, 50)];
pc.backgroundColor = [UIColor blueColor];
[self.view addSubview:pc];
[pc release];
//頁數
pc.numberOfPages = 5;
//當前頁
pc.currentPage = 2;
//顏色
//頁碼顏色
pc.pageIndicatorTintColor = [UIColor redColor];
//當前頁碼顏色
pc.currentPageIndicatorTintColor = [UIColor yellowColor];
//響應事件
[pc addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
/************* UISwicth 開關 ****************/
UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(250, 150, 150, 50)];
sw.backgroundColor = [UIColor whiteColor];
[self.view addSubview:sw];
[sw release];
//開關屬性
sw.on = YES;
sw.onTintColor = [UIColor redColor];
sw.tintColor = [UIColor blueColor];
sw.thumbTintColor = [UIColor yellowColor];
//響應方法
[sw addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
}
#pragma mark - 開關
-(void)switchAction:(UISwitch *)sw{
NSLog(@"%d",sw.on);
if (sw.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{
//獲取視圖對象的方式
//1.tag值
//2.屬性
if (seg.selectedSegmentIndex == 0) {
//transition 過度動畫
//參數一:開始視圖
//參數二:結束視圖
//參數三:持續時間
//參數四:動畫選項
//參數五:完成動畫之后調用的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);
}