UIControl

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);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • //addTarget:action:forControlEvents: //添加响应事件(满足什么条件下 让...
    肉肉要次肉阅读 244评论 0 1
  • UIControl 控制类 主要学习了分段控制器、滑块控制器、页码控制器、开关、步进控制器 一、分段控制器UISe...
    青花_阅读 363评论 0 0
  • // UIControl控制类 // addTarget:action:forControlEvents //添加...
    Devili阅读 308评论 0 0
  • //准备工作 1.删除Main 2.ARC->MRC(YES->No) 3.删除文件(ViewConTroller...
    爱吃芒果的淼小猪阅读 411评论 1 1
  • 第二十天的时候用了重复来设置例行流程,但在这两天的实践里出现了很神奇的一幕: 流程中的动作完成之后,接下来它会立马...
    繁杰杰阅读 372评论 0 0