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

后端 未结 5 1016
时光说笑
时光说笑 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:34

    Swift - For a red strikethrough font in a button title:

    let attributedStringForInvalid = NSAttributedString(string: "I'm Invalid!", attributes: [
      NSStrikethroughStyleAttributeName: true,
      NSForegroundColorAttributeName: UIColor.redColor()
      ])
    myButton.setAttributedTitle(attributedStringForInvalid, forState: UIControlState.Normal)
    

提交回复
热议问题