You need to convert your HTML formatted string into NSAttributedString, then set that attributed string as the text of your label.
You can convert your HTML formatted string to NSAttributedString using the below extension
extension NSAttributedString {
internal convenience init?(html: String) {
guard let data = html.data(using: String.Encoding.utf16, allowLossyConversion: false) else {
return nil
}
guard let attributedString = try? NSMutableAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) else {
return nil
}
self.init(attributedString: attributedString)
}
}
You can use above extension like this: let attributedString = NSAttributedString(html: ""<html><body> Some html string </body></html>"")
Then you can set the attributed string as the text of your UILabel using myLabel.attributedText = attributedString