How to set UISwitch border color?

≯℡__Kan透↙ 提交于 2019-12-21 07:54:54

问题


My app has done:

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

And here is what I have when on:

and off:

I need to make UISwitch border visible like in Settings.app:


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/21959403/how-to-set-uiswitch-border-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!