UISegmentedControl自定義背景顏色和字型顏色
阿新 • • 發佈:2019-02-02
在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 set BackgroundImage:[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];