Answers for "how to show loader before content load in WKWebView using swift"

1

wkwebview start loading delegate

var loadCount: Int = 0

override func viewDidLoad() {
    super.viewDidLoad()

    startLoading()
    webview.navigationDelegate = self
    let request = URLRequest(url: url)
    webview.load(request)
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
    loadCount += 1
}

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

    loadCount -= 1

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
        if self?.loadCount == 0 {
            self?.stopLoading()
        }
    }

}
Posted by: Guest on March-23-2020

Code answers related to "how to show loader before content load in WKWebView using swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language