更改 UISwitch 图像

Change UISwitch Image

我正在创建一个切换功能。一切都按照我希望的方式进行。我唯一的问题是将图像更改为更适合我的应用程序的图像。

这是我拥有的:

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

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

这就是我想要的:

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

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

如何更改UISwitch 的图像?一定有办法……对吧?

出于政策原因,Apple 在 iOS7 中删除了用户指定自定义 UISwitch 图像的功能。所以没有直接的方法可以达到你想要的效果。

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