Created
March 13, 2017 18:57
-
-
Save ejmartin504/26fdab15ffcabeeb9f7b68418389724e to your computer and use it in GitHub Desktop.
Load HTML String into UITextView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITextView { | |
func load(HTMLString: String) { | |
guard let htmlData = HTMLString.data(using: .utf8) else { return } | |
let options: [String: Any] = [ | |
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, | |
NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue | |
] | |
let strNative = try! NSMutableAttributedString(data: htmlData, options: options, documentAttributes: nil) | |
style(strNative) | |
attributedText = strNative | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment