UISegmentedControl 分段控制器
2015-03-05 15:21
246 查看
//设置分段内容 NSArray *title = @[@"分组", @"全部"]; UIImage *image1 = [UIImage imageNamed:@"reload_30"]; UIImage *image2 = [UIImage imageNamed:@"rotate_30"]; NSArray *title2 = @[image1, image2, @"文字"]; UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:title2]; //设置默认选中的分段 control.selectedSegmentIndex = 1; control.frame = CGRectMake(0, 30, 300, 30); //替换分段内容 [control setTitle:@"你好" forSegmentAtIndex:0]; [control setImage:image1 forSegmentAtIndex:1]; //UIControlEventValueChanged [control addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged]; control.tintColor = [UIColor redColor]; // control.backgroundColor = [UIColor redColor];
- (void)change:(UISegmentedControl *)seg { //获取选中的分段 NSInteger index = seg.selectedSegmentIndex; //插入新的分段 //[seg insertSegmentWithTitle:@"插入" atIndex:0 animated:YES]; //删除原有的分段 if (seg.numberOfSegments /*获取分段数*/== 1) { [seg removeAllSegments]; //删除所有分段 } else { //删除指定下标的分段 [seg removeSegmentAtIndex:index animated:YES]; } NSLog(@"seg change...%ld", index); }
相关文章推荐
- UI day 6 UIImageView UIImage图片类 UISitch开关控件 UIStepper加减控件 U UISegmentedControl 分段控制器
- UISegmentedControl字体大小,颜色,选中颜色,左边椭圆,右边直线的Button 解决之iOS开发之分段控制器UISegmentedControl
- UISegmentedControl分段控制器
- iOS开发 UI UISegmentedControl分段控制器
- iphone UISegmentedControl分段控件
- UISegmengedControl - 分段控制器
- iOS分段控制器UISegmentedControl和开关UISwitch
- UISegmentControl 分段视图控制器
- iOS-分段控制器大全ZFJSegmentedControl
- IOS使用视图控制器和视图(五)使用 UISegmentedControl 做简单选项分组
- iOS UISegmentedControl分段按钮
- UISegmentedControl分段控制 跳转各界面
- UISegmentedControl分段控件(基础篇)
- UISegmentedControl分段控件使用
- 分段控制器--UISegmentedControl 基本用法
- UISegmentedControl 分段控件-IOS开发
- UISegmentedControl 分段控件-IOS开发
- iOS开发-分段控制器UISegmentedControl
- UISegmentedControl分段控件
- HMSegmentedControl分段控制器的学习与使用