【问题标题】:Load UIImage into a WebView Swift 4将 UIImage 加载到 WebView Swift 4
【发布时间】:2018-04-25 20:48:45
【问题描述】:

而不是像这样从URL 加载WebView

override func viewDidLoad() {
    super.viewDidLoad()

    let url = URL(string: imageUrl.urlString)
    let request = URLRequest(url: url!)
    webView.load(request)

}

override func loadView() {
    let webConfiguration = WKWebViewConfiguration()
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.uiDelegate = self

    view = webView
}

如何将UIImage 加载到Swift 4 中的WebView?

【问题讨论】:

标签: ios swift uiwebview swift4


【解决方案1】:

试试这样的东西。

let html = "<html><img src=\"datadb/DestinationGuide/Images/YourImage.png\"/> </html>"

//Save this html in `DocumentDirectory`
let saveHTML = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("temp.html")

try? html.data(using: .utf8)!.write(to: saveHTML)

//Now load this `temp.html` file in webView
webView.loadRequest(URLRequest(url: saveHTML))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 2013-08-27
    • 1970-01-01
    相关资源
    最近更新 更多