I have a label showing HTML through this NSAttributedString function. The problem is that I want to add a custom font to it, but it does not add the font.
What have I done wrong?
Here is my code:
extension String { func convertHtml() -> NSAttributedString { let titleAttributes = [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: UIFontTextStyle.headline), NSAttributedStringKey.foregroundColor: UIColor.black] guard let data = data(using: .utf8) else { return NSAttributedString() } do{ return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) }catch{ return NSAttributedString.init(string: self, attributes: titleAttributes) } } }
titleAttributesif the attributed string is created as HTML from the string.do?