Wednesday, November 11, 2015

Showing HTML text in UILabel

Please use the following steps to show html text in UILabel of swift.

if  let attrStr = NSAttributedString(
                                        data: "<b><i>this is an html text</i></b>".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
                                        options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
                                        documentAttributes: nil,
                                    error: nil){
                                    messageLabel.attributedText = attrStr

                                    }


the out put will be like the following

this is an html text