UISegmentControl/多段选择视图

来源:互联网 发布:温州淘宝运营培训学校 编辑:程序博客网 时间:2024/04/30 03:56

UISegmentControl/多段选择视图



NSArray *array=[NSArray arrayWithObjects:@"First",@"Second",@"Third", nil];

1、分段选择控件

UISegmentedControl *sc=[[UISegmentedControl alloc] initWithItems:array];

[sc setFrame:CGRectMake(50, 200, 200, 50)];

2、设置控件颜色

sc.tintColor=[UIColor redColor];

3、默认选择起始位置

sc.selectedSegmentIndex=1;


4、自适应内容,(哪个宽加宽哪个框)

sc.apportionsSegmentWidthsByContent=YES;


5、改变内容

[sc setTitle:@"Thir d" forSegmentAtIndex:2];


6、添加事件

[sc addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];

7、添加控件

[self.view addSubview:sc];

0 0
原创粉丝点击