gpt4 book ai didi

ios - 向 WKWebView 添加加载栏并选择其颜色

转载 作者:搜寻专家 更新时间:2023-11-01 06:56:26 25 4
gpt4 key购买 nike

我正在尝试将加载栏添加到我的 WebView 页面的顶部。我将在哪里添加代码。也可以更改此加载栏的颜色吗? enter image description here

    class CycleViewController: UIViewController, WKUIDelegate {

var window: UIWindow?
var webView: WKWebView!

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

}

override func viewDidLoad() {
super.viewDidLoad()

webView.backgroundColor = UIColor.clear
webView.backgroundColor = UIColor(red: 0.0196, green: 0.4, blue: 0.2902, alpha: 1.0)

webView.isOpaque = false
let myURL = URL(string: "https://jwelsh19.wixsite.com/countryday")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)

}
}

最佳答案

如果您不想要自定义 View ,则可以使用 SFSafariViewController 来实现。使用下面的代码

if let url = URL(string: "https://jwelsh19.wixsite.com/countryday") {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true

let vc = SFSafariViewController(url: url, configuration: config)
present(vc, animated: true)
}

如果您不想使用 SFSafariViewController,则将 uiprogress bar 添加到您的 webview containerview 并观察 webview 进度并相应地更新 UIProgressbar并且为了观察 webview 进度使用 webview progress observer

    webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
progressView.progress = Float(webView.estimatedProgress)
}
}

关于ios - 向 WKWebView 添加加载栏并选择其颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53147793/

25 4 0