Skip to content

Instantly share code, notes, and snippets.

@johncodeos
Created May 1, 2016 10:49
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 johncodeos/20fd572fbc2a9181fcc9bf24b669716f to your computer and use it in GitHub Desktop.
Save johncodeos/20fd572fbc2a9181fcc9bf24b669716f to your computer and use it in GitHub Desktop.
use HTML tags in uitextview
extension NSData {
var attributedString: NSAttributedString? {
do {
return try NSAttributedString(data: self, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding], documentAttributes: nil)
} catch let error as NSError {
print(error.localizedDescription)
}
return nil
}
}
extension String {
var utf8Data: NSData? {
return dataUsingEncoding(NSUTF8StringEncoding)
}
}
let htmlStringCode = "<strong>Hi there!</strong"
htmlStringCode.utf8Data?.attributedString
//If you use UItextView,then is youruitextviewname.attributedText = htmlStringCode.html2AttributedString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment