如何在 Swift3 中为我的标签加粗 html 文本



我在一个视图的中心只有一个标签。我想加粗我的标签的某些部分。我可以做到,但是当我这样做时,我失去了标签的大小。我找到了一些线程,但没有人可以帮助我解决这个问题。

这是我使用的代码:

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
}

加粗文本后,使用 boundingRectWithSize:option:context 重新计算属性化标签的大小

最新更新