UISwitch setOn(:, animated:) does not work as document

前端 未结 3 916
失恋的感觉
失恋的感觉 2021-02-08 00:42

As Apple\'s document write, UISwitch\'s function setOn(on: Bool, animated: Bool) does not send action. It works fine before iOS 10, but it will send ac

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-08 00:54

    I found these solutions to partially work. However, when I used switch.setOn(false, animated: true) the onTint color would appear white in the off position. I'm assuming this is a bug but I worked around this by using this:

    switch.setOn(false, animated: true)
    switch.onTintColor = .clear
    

    Don't forget to reset the onTint color when you're ready to allow the switch to be toggled on, if applicable.

    switch.onTintColor =  // Use nil to use the default onTint for UISwitch
    

    Hopefully this helps save someone a little time.

提交回复
热议问题