将UIIMAGE加载到WebView Swift 4中



而不是从 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

尝试这样的东西。

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))

相关内容

  • 没有找到相关文章

最新更新