【问题标题】:Setting custom switch设置自定义开关
【发布时间】:2013-08-20 10:22:38
【问题描述】:

我发现了这个Former topic,关于如何在 iOS 6 上自定义开关。

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

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

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

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

【问题讨论】:

    标签: ios customization uiswitch


    【解决方案1】:

    在 iOS 7 下,On-Image 和 Off-Image 不再起作用。

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

    “在 iOS 7 中,此属性无效。”

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-12-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-02-28
          • 1970-01-01
          相关资源
          最近更新 更多