I have a Url that when I run it it displays html. I need to use url to display the contents in my iOS app. How do I do that? The examples I have found use WebKit, and I don't want to use webkit because I don't want the user to have the ability to use it as a website
1 Answer
You can use UILabel to display an attributed string parsed with your html string.
Here is the code in Swift 4
extension String {
func toHtmlString() -> NSAttributedString? {
guard let data = self.data(using: String.Encoding.utf16, allowLossyConversion: false) else { return nil }
guard let html = try? NSMutableAttributedString(
data: data,
options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil) else { return nil }
return html
}
}
1 Comment
grace
Hi, please check my image above. I only want the yellow parts displayed
WKWebViewand you don't need to show previous page button nor URL bar.