How to display html formatted text in ios label

前端 未结 7 1398
逝去的感伤
逝去的感伤 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:29

    for Swift 2.0:

    var attrStr = try! NSAttributedString(
            data: "text".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
            options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
            documentAttributes: nil)
    label.attributedText = attrStr
    

提交回复
热议问题