Change UISwitch Shortcut

I need to change the UISwitch label to ON-OFF to YES-NO.

I want this method to be implemented in a separate class, and then accessed by other classes.

I tried to implement the fragments provided in the cooks book, but without success

+6
ios
source share
2 answers

you can use images for on and off

 @property(nonatomic, retain) UIImage *offImage; @property(nonatomic, retain) UIImage *onImage; 

image size is 77 * 27

+1
source share

UISwitch uses images for drawing. To change the UISwitch text, you need to set the onImage and offImage UISwitch to use images with your custom text. This can be done directly on the UISwitch instance or using UIAppearance to configure your own image in all instances of UISwitch in your application:

 [[UISwitch appearance] setOnImage:onImage]; [[UISwitch appearance] setOffImage:offImage]; 

Sorry, install custom inc. and off Images for UISwitch does not work in iOS 7 or later. From the documentation :

In iOS 7, this property is not valid. In iOS 6, this image is the internal content of the switch. The specified image is arranged with round wallpaper and thumb to create the final look.

And it was not marked as obsolete. Unfortunately, in iOS 8, this seems to be the case. UISwitch color UISwitch still works, but using custom images does not work. To configure the images (and therefore the text) of the switch, you will have to use your own management class.

+1
source share

All Articles