Last active
December 19, 2016 09:40
-
-
Save masamichiueta/67d21931ffa504514adfe7b11a2c8b32 to your computer and use it in GitHub Desktop.
This file contains 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
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
do { | |
let htmlText: String = | |
"<html><head></head><body><h1>Hello World</h1><a href=\"https://www.apple.com\">link</a><p>This is a sample text</p><pre>This is also sample pre text</pre></body></html>" | |
let encodedData = htmlText.data(using: String.Encoding.utf8)! | |
let attributedOptions : [String : Any] = [ | |
NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType as Any, | |
NSCharacterEncodingDocumentAttribute: NSNumber(value: String.Encoding.utf8.rawValue) as Any, | |
] | |
let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) | |
self.textView.attributedText = attributedString | |
} catch { | |
fatalError("Unhandled error: \(error)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment