分段控件UISegmentedControl
2015-08-29 20:51
429 查看
分段控件UISegmentedControl继承与UIControl
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"全部商家", @"优惠商家", @"我的"]]; segmentedControl.center = CGPointMake(182, 45); // 每个segment的大小默认平分整个segmentedControl的大小,如果把apportionsSegmentWidthsByContent设置为YES,会根据内容来分配每一个segment的大小。 segmentedControl.apportionsSegmentWidthsByContent = YES; // 设置当前选中segment下标 segmentedControl.selectedSegmentIndex = 1; // 选中瞬间有效果,之后没有,恢复(不怎么用) // segmentedControl.momentary = YES; // 字体颜色 segmentedControl.tintColor = [UIColor orangeColor]; // segmentedControl.frame = CGRectMake(10, 30, 345, 30); // 给segmentedControl添加事件 [segmentedControl addTarget:self action:@selector(doTapSegmentedControl:) forControlEvents:(UIControlEventValueChanged)]; [self.view addSubview:segmentedControl]; [segmentedControl release];
- (void)doTapSegmentedControl:(UISegmentedControl *)segmentControl { NSLog(@"O(∩_∩)O哈哈~"); switch (segmentcontrol.selectedSegmentIndex) { case 0: self.view.backgroundColor = [UIColor redColor]; break; case 1: self.view.backgroundColor = [UIColor yellowColor]; break; case 2: self.view.backgroundColor = [UIColor blueColor]; break; default: break; } }
相关文章推荐
- 如何拉伸有透明区域的png图片来做UIButton的背景图片
- Hadoop 管理工具HUE配置-HBase配置
- UVa 1121 - Subsequence(尺取法)
- iPhone开发之UIScrollView滚动组件的使用(七)利用NSTimer计时器和UIPageControl组件代码实现图片轮播器
- UINavigationController
- ios中UIImagepickcontroller在只支持横屏或者竖屏情况下崩溃解决办法
- [刷题]N-Queens II
- shouldInterceptRequest和shouldOverrideUrlLoading
- IOS上 关于状态栏的相关设置(UIStatusBar)和preferredStatusBarStyle不执行问题
- UIImageView和UIButton的共同点和区别
- UI_动画
- UI_基类
- UI21_多线程
- UIPageControll
- UI20_KVO
- UIScrollView
- UI19_数据库1
- UITabBarItem 只有图片,没有文字,图片居中
- MR案例:输出/输入SequenceFile
- MR案例:小文件合并SequeceFile