change text of button and disable button in iOS

后端 未结 8 891
Happy的楠姐
Happy的楠姐 2020-12-23 12:52

How do you change the text of the button and disable a button in iOS?

8条回答
  •  清酒与你
    2020-12-23 13:44

    SWIFT 4 with extension

    set:

    // set button label for all states
    extension UIButton {
        public func setAllStatesTitle(_ newTitle: String){
            self.setTitle(newTitle, for: .normal)
            self.setTitle(newTitle, for: .selected)
            self.setTitle(newTitle, for: .disabled)
        }
    }
    

    and use:

    yourBtn.setAllStatesTitle("btn title")
    

提交回复
热议问题