gpt4 book ai didi

ios - 将 UIImage 加载到 WebView Swift 4

转载 作者:行者123 更新时间:2023-11-28 14:48:42 24 4
gpt4 key购买 nike

而不是像这样从 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
}

如何在 Swift 4 中将 UIImage 加载到 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))

关于ios - 将 UIImage 加载到 WebView Swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50020635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com