- (void)viewDidLoad {
[super viewDidLoad];
NSArray *items = @[@"消息", @"电话"];
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:items];
segment.frame = CGRectMake(40, 100, 295, 30);
// 添加一个新的Item到segment中
[segment insertSegmentWithTitle:@"眼神" atIndex:1 animated:YES];
// 设置选择的Item
segment.selectedSegmentIndex = 0;
// 主题颜色
segment.tintColor = [UIColor orangeColor];
// 添加事件
[segment addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segment];
}
- (void)segmentValueChanged:(UISegmentedControl *)segment
{
// 当前选择哪一人Item
// selectedSegmentIndex 当前选的是哪一个
NSString *selectedIndexTitle = [segment titleForSegmentAtIndex:segment.selectedSegmentIndex];
NSLog(@"%@", selectedIndexTitle);
}
相关文章
- 02-26mint ui的tabBar监听路由变化实现tabBar切换
- 02-26UI的一些方法(按钮和线)
- 02-26python-如何开发基于curses的UI?
- 02-26HaaS UI基础教学十:IoT平台连接
- 02-26The different between ng-grid & ui-grid
- 02-26【Android】Error obtaining UI hierarchyError while obtaining UI hierarchy XML file: com.android...
- 02-26UI基础
- 02-26vue 之 用Element ui 写一个简单的后台界面
- 02-26Element UI 图片上传
- 02-26vue 提交form表单,含图片,element-ui