Search code examples
iosswiftwebviewwkwebview

How to show image while url is loading


I am working on a WebView app. I can open my link on WebView but i want to show a loading image while url is loading. How to show a loading image while url is loading?


Solution

  • You can resolve it in 2 different ways

    1. Inject JS code which will check document.ready state and show an image while not
    2. Add UIImageVIew as subview then

    set isHidden property of the subview as false in WKNavigationDelegate method

    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!)

    and as true in

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)