Image for post
Image for post

Let’s use a spinner to show the page loading process when using WebView.

Image for post
Image for post
Image for post
Image for post
@IBOutlet var spinner: UIActivityIndicatorView!
Class DetailViewController: UIViewController, UIWebViewDelegate {
….
Override func viewDidLoad () {
Self.webView.delegate = self
// webView is the IBOutlet name of the WebView
}
Func webViewDidStartLoad (webView: UIWebView) {
// When WebView starts loading the page
Self.spinner.startAnimating ()
}
Func webViewDidFinishLoad (webView: UIWebView) {
// When WebView finished loading the page
Self.spinner.stopAnimating ()
}
Func webView (webView: UIWebView, didFailLoadWithError error: NSError?) {
// When WebView fails to load the page
Self.spinner.stopAnimating ()
}

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store