How to prevent UIButton from flashing when updating the title

前端 未结 9 1030
旧巷少年郎
旧巷少年郎 2021-01-30 04:41

When I call setTitle on a UIButton, the button flashes in iOS 7. I tried setting myButton.highlighted = NO, but that didn\'t stop the button from flashing.

[myBu         


        
9条回答
  •  伪装坚强ぢ
    2021-01-30 05:32

    Another trick

    @IBOutlet private weak var button: UIButton! {
        didSet {
            button.setTitle(title, for: .normal)
        }
    }
    

    This works only if you know the value of the title without making any API calls. The button's title will be set before the view is loaded so you won't see the animation

提交回复
热议问题