Implement the delegate of Uiwebview to receive its status changes. When you start loading the webview you put something on the screen (image, Activity Indicator, HUD). When it finishes loading, either successfully or error, you remove it.
For example, to display an image while webview loads:
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var myWebView: UIWebView!
var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL (string: "https://answall.com")
let requestObj = NSURLRequest(URL: url!)
myWebView.loadRequest(requestObj)
myWebView.delegate = self
addLoaderImage()
}
func webViewDidFinishLoad(webView: UIWebView) {
removeLoaderImage()
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
removeLoaderImage()
}
func addLoaderImage() {
imageView = UIImageView(frame: myWebView.frame)
imageView.image = UIImage(named: "loadingWebView.png")
self.view.addSubview(imageView)
}
func removeLoaderImage() {
imageView.removeFromSuperview()
imageView = nil
}
}
All right, I added a hub called Mbprogresshub in cocados put the Uiwebviewdelegate and the two methods of it, I just found a bad thing, it really waits all page load to exit the effect of the load, I’m loading a wordpress site that is very slow :(
– Gabriel Rodrigues