How to display html formatted text in ios label

前端 未结 7 1376
逝去的感伤
逝去的感伤 2020-12-24 00:55

I would like to display html formatted text on a UILabel in IOS.

In Android, it has api like this .setText(Html.fromHtml(somestri

相关标签:
7条回答
  • 2020-12-24 01:56

    You could try an attributed string:

    var attrStr = NSAttributedString(
            data: "<b><i>text</i></b>".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true),
            options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
            documentAttributes: nil,
            error: nil)
    label.attributedText = attrStr
    
    0 讨论(0)
提交回复
热议问题