0

Below code works well in iOS 12 or below, but fails to append in iOS 13, as it prints only First Line and fails to print Extra Text.

    let formattedString = NSMutableAttributedString()                                                                 
    formattedString.append(NSAttributedString(string: "First Line\n" ,
                                                          attributes:[NSAttributedStringKey.font:UIFont.systemFont(ofSize: 8.0), NSAttributedStringKey.foregroundColor : UIColor.white]))
    formattedString.append(NSAttributedString(string: "Extra Text", attributes: [NSAttributedStringKey.foregroundColor : UIColor.white]))
    self.setAttributedTitle(formattedString, for: .normal)
geko
  • 1
  • 1
    What do you mean by "print"? How to you print it? – Arik Segal Dec 09 '19 at 12:01
  • I used word 'printing' for example .. I'm assigning it to a button as `self.setAttributedTitle`.. Any Solution for NSMutableAttributedString() ? – geko Dec 09 '19 at 12:49
  • It's probably an issue with the new line character. See if this can help: https://stackoverflow.com/questions/604632/how-do-you-add-multi-line-text-to-a-uibutton – Arik Segal Dec 09 '19 at 12:54
  • There is a difference because it's applied to a UIButton and not. Does it work on a UILabel/UITextView? If yes, the issue is with UIButton. Update your question with theses info, adding then a tag UIButton if that's the case might help, and that's not only `NSMutableAttributedString` issue. – Larme Dec 09 '19 at 13:41
  • Thanks all.. works after I added these lines `self.titleLabel?.textAlignment = .center self.titleLabel?.adjustsFontSizeToFitWidth = true; self.titleLabel?.lineBreakMode = .byClipping; self.titleLabel?.numberOfLines = 2; let formattedString = NSMutableAttributedString()` – geko Dec 10 '19 at 10:44

0 Answers0