Skip to content

Instantly share code, notes, and snippets.

@ejmartin504
Created March 13, 2017 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejmartin504/26fdab15ffcabeeb9f7b68418389724e to your computer and use it in GitHub Desktop.
Save ejmartin504/26fdab15ffcabeeb9f7b68418389724e to your computer and use it in GitHub Desktop.
Load HTML String into UITextView
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