UISwitch set on/off Image

二次信任 提交于 2019-11-30 20:02:48

Use a UIButton instead.

let switchButton = UIButton(type: .Custom)
switchButton.selected = true
switchButton.setImage(UIImage(named: "on-switch"), forState: .Selected)
switchButton.setImage(UIImage(named: "off-switch"), forState: .Normal)

Use switchButton.selected instead of switch1.on. You'll have to toggle switchButton.selected when it is tapped (switchButton.selected = !switchButton.selected).

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