Programmatically change title of UIButton whose title was set in IB as attributed

后端 未结 5 1039
时光说笑
时光说笑 2021-01-01 13:52

I have changed titles of UIButtons before using:

- (void)setTitle:(NSString *)title forState:(UIControlState)state

But I\'ve r

5条回答
  •  死守一世寂寞
    2021-01-01 14:46

    Attributed titles are obtained via

    - (NSAttributedString *)attributedTitleForState:(UIControlState)state
    

    and set via

    - (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state
    

    Formatting the NSAttributedString object is a bit complicated, but setting it to nil will clear the title and that's what I needed.

提交回复
热议问题