UISwitch 0/1 to ON/OFF

2019-08-16 08:39发布

问题:

I created a UISwitch to use with my project, and I get a UISwitch that says 0/1 instead of the usual OFF/ON. I find this quite awkward really and was wondering if there was some text property I could edit or something.

I've read that subclassing on the UISlider was the only way to do this, but I'm hoping that someone can point me in the right direction.

回答1:

There's no built-in way to change the text. It's localized. Depending on the language set up in your simulator / on your device, it will look different. For example, it looks like 0/1 in French.

If you want to customize it anyway, check out RCSwitch, an open-source replacement for UISwitch that is much more customizable, including width, color, text, etc.