UISegmentedControl 的使用
来源:互联网 发布:蘑菇战争2 数据 编辑:程序博客网 时间:2024/05/08 11:15
直接上代码:
//UISegmentedControl 对象的创建 //参数为数组,数组为字符串数组,表示各个分段的标题,数组的对象个数确定了分段个数。 UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:@[@"黄色", @"红色", @"(~﹃~)~zZ", @"☺"]]; segmentControl.frame = CGRectMake(30, 100, CGRectGetWidth(self.view.bounds) - 60, 40); //设置选中分段的下标 segmentControl.selectedSegmentIndex = 1; //当设置完默认选中的下标后,为了能够把响应方法,需要手动调用对应的方法,并把当前分段空间对象当做参数传入方法,方法内部就会根据该分段控件的选中下标做出操作。 [self handleSegmentAction:segmentControl]; //通过设置分段控件的表面着色来修改其外观颜色,并且选中颜色随着边框颜色的改变而改变 segmentControl.tintColor = [UIColor blackColor]; //背景颜色// segmentControl.backgroundColor = [UIColor brownColor]; //当给分段添加图片时,需要更改 image 对象的渲染模式为原始渲染模式,否则该图片会跟随控件的 tintColor 变成纯色色块, UIImage *firstImage = [[UIImage imageNamed:@"2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; //设置指定分段下标的图片 [segmentControl setImage:firstImage forSegmentAtIndex:0]; //绑定响应方法 [segmentControl addTarget:self action:@selector(handleSegmentAction:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:segmentControl]; [segmentControl release];- (void)handleSegmentAction:(UISegmentedControl *)sender { switch (sender.selectedSegmentIndex) { case 0: self.view.backgroundColor = [UIColor yellowColor]; NSLog(@"黄色"); break; case 1: self.view.backgroundColor = [UIColor redColor]; NSLog(@"红色"); break; case 2: self.view.backgroundColor = [UIColor blueColor]; NSLog(@"蓝色"); break; case 3: self.view.backgroundColor = [UIColor greenColor]; NSLog(@"绿色"); break; } NSLog( @"%s", __FUNCTION__ ) ;}
0 0
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- UISegmentedControl的使用
- UISegmentedControl的详细使用
- UISegmentedControl 的使用
- UISegmentedControl的使用
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- UISegmentedControl的初级使用
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- UISegmentedControl的详细使用
- ios UISegmentedControl的使用
- UISegmentedControl的详细使用
- Python中utf-8与utf-8-sig两种编码格式的区别
- 理解Hibernate延迟加载策略
- Android Studio 问题 - Clear Read-Only Status
- Asp中JSON的使用
- 正则表达式集合
- UISegmentedControl 的使用
- 【零基础学习iOS开发】【02-C语言】10-函数
- Go语言简介
- LintCode Delete Node in the Middle of Singly Linked List 在O(1)时间复杂度删除链表节点
- Magento通过分类id获取该分类下的产品(entity_id、type_id、sku、created_at、updated_at、status、visibility)
- 二级指针
- 【零基础学习iOS开发】【02-C语言】09-流程控制
- Tcpclient简单聊天程序
- caffe study(3) 关于激活函数以及loss function