Open TrungKhanhNguyen opened 4 years ago
extension String {
func convertHtml() -> AttributedString {
guard let data = data(using: .utf8) else { return AttributedString() }
if let attributedString = try? AttributedString(data: data, options: [.documentType: AttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) {
return attributedString
} else {
return AttributedString()
}
}
}
example:
self.textView.attributedText = tempText.convertHtml().set(style: style)
@petkrein Why would you want to convert HTML to NSAttributedString using AttributedString's method? Doesn't the library do automatically?
using convertHtml is extremely slow I have a page with hundred html titles, and loading time went from 2s to 100s I was hoping this library was doing just that
@altagir altagir:
using convertHtml is extremely slow I have a page with hundred html titles, and loading time went from 2s to 100s I was hoping this library was doing just that
As @TrungKhanhNguyen reported, the library does not appear to support this. I ran into the same problem and helped myself with the extension. And yes, it's very slow.
I want display some HTML String for UITextView but its only display raw text. I dont know why
Can you help me? Thanks I'm using xcode 11.4 & catalina 10.15.4