正在设置自定义开关



我发现了关于如何在iOS 6上自定义开关的前一个主题。

但我不知道如何使用答案:

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

我必须把这两行放在哪里?在.h文件或.m文件中?在ViewController文件中,我的开关在哪里?

此外,我如何设置我的图像和这两行之间的链接(我必须将我的图像称为"offimage.png"one_answers"onimage.png"?)

在iOS 7下,打开和关闭图像不再工作。

https://developer.apple.com/library/ios/documentation/uikit/reference/UISwitch_Class/Reference/Reference.html

"在iOS 7中,此属性无效。"

onImageoffImageUISwitch的属性-您不需要将代码添加到代码中。创建UISwitch实例后,可以通过将这些属性设置为适当的UIImage实例来设置打开和关闭图像。

要完成我的问题,我只需要把这一行放在.m文件中:

switch_name.onImage=[UIImage imageNamed:@"image_name.jpg"];

最新更新