您的位置:首页 > 产品设计 > UI/UE

UISegmentControl

2016-01-02 18:17 393 查看
创建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]; //添加点击事件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: