//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.tintColor = [UIColor redColor];
//插入新的分段
[seg insertSegmentWithImage:@"" atIndex:2 animated:YES];
//添加显示事件(通过下标值得变化触发方法)
[seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventEditingChanged];
#pragma mark - 分段控制器
-(void)segAction:(UISegmentedControl *)seg{
//获取视图对象的方式
//1.tag值
//2.属性
if (seg.selectedSegmentIndex == 0) {
//transition 过度动画
//参数1:开始视图
//参数2:结束视图
//参数3:持续时间(以秒为单位)
//参数4:动画选项
//参数5:完成动画之后调用的block
[UIView transitionFromView:self.greenV toView:self.redV duration:1 options:(UIViewAnimationOptionTransitionFlipFromLeft) completion:^(BOOL finished) {
}];
}
if (seg.selectedSegmentIndex == 1) {
[UIView transitionFromView:self.redV toView:self.greenV duration:1 options:(UIViewAnimationOptionTransitionCurlUp) completion:^(BOOL finished) {
}];
}
//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 lightGrayColor];
//添加响应事件
[sl addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
//滑动范围
//最小值
sl.minimumValue = -100;
//最大值
sl.maximumValue = 1000;
//更新滑块的起始点
sl.value = -100;
#pragma mark - 滑块控制器
-(void)sliderAction:(UISlider *)sl{
NSLog(@"%f",sl.value);
}
//UIPageControl 页码控制器
UIPageControl *pc = [[UIPageControl alloc]initWithFrame:CGRectMake(50, 150, 100, 50)];
pc.backgroundColor = [UIColor blackColor];
[self.view addSubview:pc];
[pc release];
//页数
pc.numberOfPages = 4;
//当前页
pc.currentPage = 3;
//当前页颜色
pc.currentPageIndicatorTintColor = [UIColor greenColor];
//响应事件
[pc addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
#pragma mark - 页码控制器
-(void)pageAction:(UIPageControl *)page{
NSLog(@"%ld",page.currentPage);
}
//UISwitch开关
UISwitch *sw = [[UISwitch alloc]initWithFrame:CGRectMake(250, 150, 100, 50)];
sw.backgroundColor = [UIColor whiteColor];
[self.view addSubview:sw];
[sw release];
//开关属性
sw.on = YES;
//开启时颜色
sw.onTintColor = [UIColor yellowColor];
//关闭时边框颜色
sw.tintColor = [UIColor lightGrayColor];
//按钮颜色
sw.thumbTintColor = [UIColor cyanColor];
//响应方法
[sw addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
#pragma mark - 按钮开关控制器
-(void)switchAction:(UISwitch *)sw{
if (sw.on) {
NSLog(@"开启");
}else {
NSLog(@"关闭");
}
}