我试图在 WebView 中加载链接时显示 SVProgressHUD,换句话说,我有一个包含链接的 WebView,我想在点击该链接时显示 SVProgressHUD。
这是我的 webiew 代码:
class ViewController: UIViewController, WKNavigationDelegate {
@IBOutlet weak var webView:WKWebView?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
.lightContent
}
override func viewDidLoad()
{
super.viewDidLoad()
webView?.navigationDelegate = self
//webView?.addSubview(Spinner)
SVProgressHUD.show(withStatus: ("Loading ..."))
SVProgressHUD.setBackgroundColor(#colorLiteral(red: 0.3466703892, green: 0.7427461743, blue: 0.6237300038, alpha: 1))
SVProgressHUD.setForegroundColor(#colorLiteral(red: 1, green: 1, blue: 1, alpha: 1))
SVProgressHUD.setMinimumSize(CGSize(width: 120, height: 120))
SVProgressHUD.setRingThickness(7.0)
SVProgressHUD.setRingRadius(CGFloat(40.0))
let request = URLRequest(url: URL(string: "https://luhom-app.com/")!)
webView?.load(request)
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(reloadWebView(_:)), for: .valueChanged)
refreshControl.backgroundColor = #colorLiteral(red: 0.3466703892, green: 0.7427461743, blue: 0.6237300038, alpha: 1)
webView?.scrollView.addSubview(refreshControl)
}
@objc func reloadWebView(_ sender: UIRefreshControl) {
webView?.reload()
SVProgressHUD.show(withStatus: ("Refreshing ..."))
sender.endRefreshing()
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
DispatchQueue.main.async {
SVProgressHUD.showSuccess(withStatus: ("Done!"))
SVProgressHUD.dismiss()
}
}
}
请问有什么帮助吗?