ActiveLabel.swift
ActiveLabel.swift copied to clipboard
HTML tags not working properly
func htmlAttributed(size: CGFloat) -> NSAttributedString? {
do {
let htmlCSSString = "<style>" +
"html *" +
"{" +
"font-size: \(size)pt !important;" +
"}</style> \(self)"
guard let data = htmlCSSString.data(using: String.Encoding.utf8) else {
return nil
}
return try NSAttributedString(data: data,
options: [.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
} catch {
print("error: ", error)
return nil
}
}
let text = "<b> Bold</b><i> Italic</i> <u>Underline</u>"
self.activeLabel.attributedText = text.htmlAttributed(size: 15)
Output Bold Italic Underline
Its returning everything in bold instead of desired output.
@schickling, @maziyarpanahi , @polqf please look into this.