1

I have only a label in the center of one view. I want to bold some part of my label. I can do it, but when I do it, I lose the size of my label. I found some thread, but no one could help me with this problem size.

Here is the code I use:

override func viewDidAppear(_ animated: Bool) {
    let attrStr = try! NSAttributedString(
        data: "I'm a normal text and <b>this is my bold part . </b>And I'm again in the normal text".data(using: String.Encoding.unicode, allowLossyConversion: true)!,
        options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
        documentAttributes: nil)
    myLabel.attributedText = attrStr
}
rmaddy
  • 307,833
  • 40
  • 508
  • 550
Badr Filali
  • 251
  • 4
  • 20

1 Answers1

0

After you bold text, re-calculate the size of attributed label using boundingRectWithSize:option:context

Community
  • 1
  • 1
NeverHopeless
  • 10,869
  • 4
  • 34
  • 55