【iOS开发】UISegmentedControl自定义背景颜色

2017-01-15  本文已影响551人  文刂Rn

在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];
上一篇下一篇

猜你喜欢

热点阅读