change text of button and disable button in iOS

后端 未结 8 874
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")
    
    0 讨论(0)
  • 2020-12-23 13:45

    To Change Button title:

    [mybtn setTitle:@"My Button" forState:UIControlStateNormal];
    [mybtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    

    For Disable:

    [mybtn setEnabled:NO];
    
    0 讨论(0)
提交回复
热议问题