How to display html formatted text in ios label

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

    Swift 3.0

    do {
        let attrStr = try NSAttributedString(
            data: "text".data(using: String.Encoding.unicode, allowLossyConversion: true)!,
            options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
            documentAttributes: nil)
        label.attributedText = attrStr
    } catch let error {
    
    }
    

提交回复
热议问题