Display HTML text in UILabel iphone

前端 未结 11 1938
借酒劲吻你
借酒劲吻你 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条回答
  •  -上瘾入骨i
    2020-12-02 15:14

    Here is the swift 2 version:

        let htmlStringData = NSString(string: "Your HTML String here").dataUsingEncoding(NSUTF8StringEncoding)
        guard let html = htmlStringData else { return }
    
        do {
            let htmlAttrString = try NSAttributedString(data: html, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            yourLabel.attributedText = htmlAttrString
        } catch {
            print("An error occured")
        }
    

提交回复
热议问题