Set the stroke color for a UISwitch when it's on?

守給你的承諾、 提交于 2020-03-26 05:33:55

问题


I have a UISwitch that needs to have the same style when it's on as when it's off. The only difference would be where the little circle is.

It looks like this when it's off:

… which is good. But when I turn it on, the stroke disappears:

How do I make it keep the stroke when it's on? If that isn't possible, can I at least make it tinted when it's off and not just when it's on?


回答1:


Apple may reject your app for not showing a different color for the On state, however I believe this is what you're wanting: This will show the 'stroke' for each state now.

@property (nonatomic, strong) IBOutlet UISwitch *theSwitch;

self.theSwitch.layer.borderColor = [UIColor colorWithRed:229.0/255.0 green:229.0/255.0 blue:229.0/255.0 alpha:1.0].CGColor;
self.theSwitch.layer.borderWidth = 1.5;
self.theSwitch.layer.cornerRadius = 31.0/2.0;

Results:



来源:https://stackoverflow.com/questions/24895842/set-the-stroke-color-for-a-uiswitch-when-its-on

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