更改关闭状态和边框颜色的 UISwitch 默认颜色
change UISwitch default color for OFF state and border colors
我参考了以下How to change UISwitch default color for OFF state?
我有以下代码
- (void)viewDidLoad {
[super viewDidLoad];
self.termSwitch.layer.cornerRadius = 16.0;
[self SwitchStatus];
}
- (IBAction)SwitchStatusChange:(id)sender {
[self SwitchStatus];
}
- (void)SwitchStatus {
if ( self.termSwitch.on) {
[ self.termSwitch setThumbTintColor:[UIColor whiteColor]];
[ self.termSwitch setBackgroundColor:[UIColor clearColor]];
[ self.termSwitch setOnTintColor:[UIColor clearColor]];
}else{
[ self.termSwitch setTintColor:[UIColor clearColor]];
[ self.termSwitch setThumbTintColor:[UIColor whiteColor]];
[ self.termSwitch setBackgroundColor:[UIColor colorWithRed:0.384f green:0.859f blue:0.427f alpha:1.00f]];
}
}
我无法为开关放置白色边框,默认情况下开关不平滑
我已经检查了下面的 link 但它对我不起作用
How to set UISwitch border color?
您的代码毫无意义。您没有做任何会改变边框颜色的事情,所以边框颜色自然不会改变。如果你想要不同的边框颜色,设置边框颜色:
// s is a UISwitch
s.layer.borderWidth = 1
s.layer.borderColor = UIColor.whiteColor().CGColor
s.layer.cornerRadius = 16
我参考了以下How to change UISwitch default color for OFF state?
我有以下代码
- (void)viewDidLoad {
[super viewDidLoad];
self.termSwitch.layer.cornerRadius = 16.0;
[self SwitchStatus];
}
- (IBAction)SwitchStatusChange:(id)sender {
[self SwitchStatus];
}
- (void)SwitchStatus {
if ( self.termSwitch.on) {
[ self.termSwitch setThumbTintColor:[UIColor whiteColor]];
[ self.termSwitch setBackgroundColor:[UIColor clearColor]];
[ self.termSwitch setOnTintColor:[UIColor clearColor]];
}else{
[ self.termSwitch setTintColor:[UIColor clearColor]];
[ self.termSwitch setThumbTintColor:[UIColor whiteColor]];
[ self.termSwitch setBackgroundColor:[UIColor colorWithRed:0.384f green:0.859f blue:0.427f alpha:1.00f]];
}
}
我无法为开关放置白色边框,默认情况下开关不平滑
我已经检查了下面的 link 但它对我不起作用
How to set UISwitch border color?
您的代码毫无意义。您没有做任何会改变边框颜色的事情,所以边框颜色自然不会改变。如果你想要不同的边框颜色,设置边框颜色:
// s is a UISwitch
s.layer.borderWidth = 1
s.layer.borderColor = UIColor.whiteColor().CGColor
s.layer.cornerRadius = 16