UISegmentControl

创建UISegmentControl对象

UISegmentedControl *segmented = [[UISegmentedControl alloc] initWithItems:@[@"北京", @"上海", @"广州"]];

segmented.frame = CGRectMake(100, 100, 200, 40); 

segmented.selectedSegmentIndex = 2; //默认选中某个分段,按下标

segmented.tintColor = [UIColor greenColor]; //设置segmentControl的渲染颜色

[segmented setWidth:60 forSegmentAtIndex:1]; //单独设置某个分段的宽(此方法会在原有宽度的基础上压缩其它分段的宽度).

//设置分段控件上的字体的属性

NSDictionary *textDic = @{NSFontAttributeName:[UIFont SystemFontOfSize:16], NSForegroundColorAttributeName:[UIColor redColor] };

[segmented setTittleTextAttributes:textDic forState:UIControlStateNormal];

[segmented addTarget:self action:@selector(handleSegment:) forControlEvents:UIControlEventValueChanged]; //添加点击事件

posted @ 2016-01-02 18:17  侯文超  阅读(206)  评论(0编辑  收藏  举报