Display HTML text in UILabel iphone

前端 未结 11 1998
借酒劲吻你
借酒劲吻你 2020-12-02 14:39

I am getting a HTML Response from a webservice Below is the HTML I am getting in response

TopicGud mrng.

\\n
11条回答
  •  没有蜡笔的小新
    2020-12-02 14:53

    The above answer in Swift 3:

        var str = " ... some html ... "
    
        let htmlStringData = NSString(string: str).data(using: String.Encoding.utf8.rawValue)
        let html = htmlStringData
    
        do {
            let htmlAttrString = try? NSAttributedString(
                    data: html!,
                    options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
                    documentAttributes: nil
            )
            agreementText.attributedText = htmlAttrString
        } catch {
            print("An error occured")
        }
    

提交回复
热议问题