How to prevent UIButton from flashing when updating the title

前端 未结 9 1035
旧巷少年郎
旧巷少年郎 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:25

    Try this, this works in newer versions of IOS:

    class CustomButtonWithNoEffect : UIButton {
        override func setTitle(_ title: String?, for state: UIControlState) {
            UIView.performWithoutAnimation {
                super.setTitle(title, for: state)
                super.layoutIfNeeded()
            }
        }
    
    }
    

提交回复
热议问题