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

UISegmentedControl自定义背景颜色和字体颜色

2016-11-21 15:13 274 查看
在UISegmentedControl的控件中,有一个设置默认颜色的

// The tintColor is inherited through the superview hierarchy. See UIView for more information.

@property(null_resettable,nonatomic,strong) UIColor *tintColor;


使用方式如下:

[_segmentedControl setTintColor:[UIColor whiteColor]];


- 设置选中时的背景色

[_segmentedControl setBackgroundImage:[UIImage imageNamed:@"selectImg"]
forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];


- 设置为选中时的背景色

[_segmentedControl setBackgroundImage:[UIImage imageNamed:@"unSelectImg"]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];


- 设置选中时字体颜色

NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:RGBA(.94, .31, .18),UITextAttributeTextColor,nil];
[_segmentedControl setTitleTextAttributes:dic forState:UIControlStateSelected];


- 设置默认字体颜色

NSDictionary *dics = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil];
[_segmentedControl setTitleTextAttributes:dics forState:UIControlStateNormal];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UISegmente