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
  • 314,917
  • 42
  • 532
  • 579
Badr Filali
  • 279
  • 5
  • 21

1 Answers1

0

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

Community
  • 1
  • 1
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56