// 创建一个数组
NSArray *array = @[@"1",@"2",@"3",@"4",@"5"];
// 创建UISegmentedControl
UISegmentedControl *segmentedcontrol = [[UISegmentedControl alloc] initWithItems:array];
segmentedcontrol.frame = CGRectMake(50, 50, 200, 50);
// 设置默认选项
segmentedcontrol.selectedSegmentIndex = 0;
// 设置字体颜色
segmentedcontrol.tintColor = [UIColor blueColor];
// 点击后恢复原样
segmentedcontrol.momentary = YES;
// 设置标题文字
[segmentedcontrol setTitle:@"0" forSegmentAtIndex:0];
// 插入标题文字
[segmentedcontrol insertSegmentWithTitle:@"0" atIndex:0 animated:YES];
// 删除单个标题文字
[segmentedcontrol removeSegmentAtIndex:0 animated:YES];
// 删除全部标题文字
[segmentedcontrol removeAllSegments];
// 获得被选中的标题文字
NSString *str = [segmentedcontrol titleForSegmentAtIndex:0];
// 设置该索引的宽度
[segmentedcontrol setWidth:50 forSegmentAtIndex:0];
// 设置该索引的外边距
[segmentedcontrol setContentOffset:CGSizeMake(10, 10) forSegmentAtIndex:0];
// 判断改索引能否被点击
[segmentedcontrol setEnabled:YES forSegmentAtIndex:0];
// 设置segmentedcontrol的背景图片
[segmentedcontrol setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];