How to set UISwitch border color?

后端 未结 3 1130
星月不相逢
星月不相逢 2021-02-19 09:11

My app has:

[[UIView appearance] setTintColor:[UIColor whiteColor]];

And here is what I have when on:

and off

相关标签:
3条回答
  • 2021-02-19 09:44

    Will you please try adding this line to your AppDelegate's didFinishLaunchingWithOptions

    [[UISwitch appearance] setTintColor:[UIColor grayColor]];
    

    This should apply the chosen Tint color on all your UISwitch controls.

    0 讨论(0)
  • 2021-02-19 09:49

    Rather than using the appearance proxies you can also use:

    [self.mySwitch setThumbTintColor:[UIColor blueColor]];
    [self.mySwitch setOnTintColor:[UIColor redColor]];
    

    ie. Use setOnTintColor for the background/border color.

    0 讨论(0)
  • 2021-02-19 09:52

    Your [[UIView appearance] setTintColor:[UIColor whiteColor]]; is interfering with the tint color of your switch. The command to set the tint color is self.mySwitch.tintColor = [UIColor grayColor]; which sets the color used to tint the outline of the switch when it is turned off.

    0 讨论(0)
提交回复
热议问题