更改UISwitch图像

时间:2018-06-27 19:17:22

标签: ios swift uiswitch

我正在创建切换功能。一切都按照我的意愿进行。我唯一的问题是将图像更改为更适合我的应用的图像。

这就是我所拥有的:

https://res.cloudinary.com/dfd4ae1lw/image/upload/v1530126510/Stackoverflow/off_switch.png

https://res.cloudinary.com/dfd4ae1lw/image/upload/v1530126510/Stackoverflow/On_Switch.png

这就是我想要的:

https://res.cloudinary.com/dfd4ae1lw/image/upload/v1530126510/Stackoverflow/On_Toggle.png

https://res.cloudinary.com/dfd4ae1lw/image/upload/v1530126510/Stackoverflow/Off_Toggle.png

如何更改UISwitch的图像?一定有办法...对吗?

1 个答案:

答案 0 :(得分:0)

由于政策原因,Apple隐含了用户无法在iOS 7中指定自定义UISwitch图像的功能。因此,没有直接的方法可以实现您想要的。

您可以使用NSButton通过切换isSelected状态来模拟它;这与与用户交互有关的isHighlighted状态完全不同,并且界面设计器允许您为不同的状态指定不同的图像。