如何在swift 3 ios中显示带有html标记和图像的内容文本
我从包含html标记和图片的API获取文本。如何显示它,我需要在哪里显示,我是说UILabel还是WebView? 我尝试使用NSAttributedString,但不是我需要的如何在swift 3 ios中显示带有html标记和图像的内容文本,html,ios,swift,webview,Html,Ios,Swift,Webview,我从包含html标记和图片的API获取文本。如何显示它,我需要在哪里显示,我是说UILabel还是WebView? 我尝试使用NSAttributedString,但不是我需要的 平台iOS 9,Swift 3您可以在webView中加载html标记 func loadHtmlCode() { let htmlCode = "<html><head><title>Wonderful web</title></head>
平台iOS 9,Swift 3您可以在webView中加载html标记
func loadHtmlCode() {
let htmlCode = "<html><head><title>Wonderful web</title></head> <body><p>wonderful web. loading html code in <strong>UIWebView</strong></></body>"
webView.loadHTMLString(htmlCode, baseURL: nil)
}
您可以在webView中加载html标记,如下所示:
func loadHtmlCode() {
let htmlCode = "<html><head><title>Wonderful web</title></head> <body><p>wonderful web. loading html code in <strong>UIWebView</strong></></body>"
webView.loadHTMLString(htmlCode, baseURL: nil)
}
我找到路了。
我在Info.plist做过
应用程序传输安全设置->允许任意加载->是
图像正在显示
和代码:
DispatchQueue.main.async {
let attrStr = try! NSAttributedString(
data: (self.detailLabelText?.data(using: String.Encoding.unicode, allowLossyConversion: true)!)!,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil)
self.detailLabel.attributedText = attrStr
self.detailLabel.textAlignment = NSTextAlignment.justified
self.detailLabel.contentMode = .scaleToFill
self.detailLabel.font = UIFont(name: "PTSans-Narrow", size: 18.0)
}
detailLabel.adjustsFontSizeToFitWidth = true
detailLabel.sizeToFit()
我找到路了。
我在Info.plist做过
应用程序传输安全设置->允许任意加载->是
图像正在显示
和代码:
DispatchQueue.main.async {
let attrStr = try! NSAttributedString(
data: (self.detailLabelText?.data(using: String.Encoding.unicode, allowLossyConversion: true)!)!,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil)
self.detailLabel.attributedText = attrStr
self.detailLabel.textAlignment = NSTextAlignment.justified
self.detailLabel.contentMode = .scaleToFill
self.detailLabel.font = UIFont(name: "PTSans-Narrow", size: 18.0)
}
detailLabel.adjustsFontSizeToFitWidth = true
detailLabel.sizeToFit()
我错过的正是Info.plist!图像内容呢?它将从uilabel中删除吗?或者它会显示出来?@Zhanserik最佳答案:你能帮我回答这个问题吗:@jazzbpn对不起,我没有使用颤振的经验。推荐编写本机应用程序。Info.plist正是我所缺少的!图像内容呢?它将从uilabel中删除吗?或者它会显示出来?@Zhanserik最佳答案:你能帮我回答这个问题吗:@jazzbpn对不起,我没有使用颤振的经验。建议编写本机应用程序。问题Webview已弃用。任何对苹果有丰富经验的人。因为webkit具有不应允许的导航。因为它们将在页面问题中丢失,Webview已弃用。任何对苹果有丰富经验的人。因为webkit具有不应允许的导航。因为它们会在页面中丢失