is it possible to update UIButton title/text programmatically?

后端 未结 12 1785
北海茫月
北海茫月 2020-12-07 19:58

I have a UIButton, that when pressed, brings up a new view where the user can change some settings. When the view is dismissed, I\'d like to update the title/t

12条回答
  •  独厮守ぢ
    2020-12-07 20:18

    Turns out the docs tell you the answer! The UIButton will ignore the title change if it already has an Attributed String to use (with seems to be the default you get when using Xcode interface builder).

    I used the following:

    [self.loginButton 
         setAttributedTitle:[[NSAttributedString alloc] initWithString:@"Error !!!" attributes:nil] 
         forState:UIControlStateDisabled];
    [self.loginButton setEnabled:NO];
    

提交回复
热议问题