Change Label of UISwitch

后端 未结 2 1295
走了就别回头了
走了就别回头了 2020-12-07 02:00

I have to change the label of a UISwitch from ON-OFF to YES-NO.

I want this method to be implemented in separate class and then accessed by other classe

相关标签:
2条回答
  • 2020-12-07 02:27

    UISwitch uses images for drawing. To change the text of a UISwitch, you would have to set the onImage and offImage properties of the UISwitch to use images with your custom text. This could be done directly on a UISwitch instance, or using UIAppearance to set your custom image across all UISwitch instances in your app:

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

    Unfortunately, setting custom on and off images for UISwitch is not functional in iOS 7 or later. From the documentation:

    In iOS 7, this property has no effect. In iOS 6, this image represents the interior contents of the switch. The image you specify is composited with the switch’s rounded bezel and thumb to create the final appearance.

    And it has not been marked as deprecated. In iOS 8 this still seems to be the case, unfortunately. Customizing the colors of a UISwitch still works, but using custom images does not. To customize the images (and thus text) of a switch you will have to use a custom control class.

    0 讨论(0)
  • 2020-12-07 02:44

    you can use images for on and off

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

    image size is of 77*27

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