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 output will be like the following:
this is an html text