Changing the text on a UISwitch

烈酒焚心 提交于 2019-11-27 04:05:01

问题


The UISwitch currently says ON and OFF. Can I change the text to YES and NO?

Would it be hard? Or do I just rephrase the question I ask the user?


回答1:


As of iOS 6, you can set

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

Docs say:

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.

The size of this image must be less than or equal to 77 points wide and 27 points tall. If you specify larger images, the edges may be clipped.




回答2:


I've done exactly this in iOS 6 with onImage and offImage, here are the images I used:




回答3:


To change the text of an UISwitch e.g. to "Foo/Bar", do the following:

((UILabel *)[[[[[[_agreeAgb subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:0]).text = @"Foo";
((UILabel *)[[[[[[_agreeAgb subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:1]).text = @"Bar";


来源:https://stackoverflow.com/questions/2711180/changing-the-text-on-a-uiswitch

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