I am trying to show SVProgressHUD while loading a link inside the WebView, in others words, I have a WebView which has a link and I want show the SVProgressHUD when I hit that link.
here is my webiew code:
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()
}
}
}
Any help on that please?