更改OFF状态和边框颜色

时间:2015-07-16 16:32:08

标签: ios uiswitch tintcolor

我参考了以下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]];
    }

}

我无法为开关设置白色边框,默认情况下开关不顺畅

enter image description here

我已查看以下链接,但它对我不起作用

How to set UISwitch border color?

1 个答案:

答案 0 :(得分:14)

你的代码毫无意义。您没有做任何会改变边框颜色的事情,因此边框颜色自然不会改变。如果您想要不同的边框颜色,设置边框颜色:

// s is a UISwitch
s.layer.borderWidth = 1
s.layer.borderColor = UIColor.whiteColor().CGColor
s.layer.cornerRadius = 16

enter image description here

相关问题