标签:
//创建数组存放选项信息
NSArray *array=[[NSArray alloc]initWithObjects:@"one",@"two",@"three", nil];
//初始化
UISegmentedControl *segment=[[UISegmentedControl alloc]initWithItems:array];
//设置坐标
segment.frame=CGRectMake(0, 20, 150, 25);
//ios7以前使用
//segment.segmentedControlStyle=UISegmentedControlSegmentCenter;
//初始时选中项
segment.selectedSegmentIndex=0;
//添加事件
[segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segment];
//添加方法,输出选中项
-(void)segmentAction:(UISegmentedControl *)segmented
{
//选中项
NSLog(@"%d",segmented.selectedSegmentIndex);
}
标签:
原文地址:http://www.cnblogs.com/kyuubee/p/4804837.html