Michael Sebastian
Michael Sebastian

Reputation: 785

Add a custom background image as my uiwebview starts to load (using Swift)

Technologies: XCode6, iOS 8.2, Swift

My web view takes a few seconds to fully load and I wanted to add a background image while users were waiting. I can easily change the color of the background, but what is the best way to add a background image?

override func viewDidLoad() {
    super.viewDidLoad()
    webView.delegate = self
    self.navigationController?.toolbarHidden = false;
    openLoadingPopup()
    webView.backgroundColor = UIColor.blackColor();
    if browserHistory.count < 1 {
        backButton.enabled = false
    }
}

func webViewDidFinishLoad(webView: UIWebView) {
    UIApplication.sharedApplication()
        . networkActivityIndicatorVisible = false
    closeLoadingPopup()
    if cacheURL {
        ++browserHistoryIndex
        browserHistory.insert(webView.request!.URL, atIndex:   
        browserHistoryIndex)
        backButton.enabled = browserHistoryIndex != 0
    }
}

Upvotes: 1

Views: 1126

Answers (1)

Erik
Erik

Reputation: 12858

I would suggest using a UIImageView that covers the UIWebView while it is loading. Once the webViewDidFinishLoad is called, you can hide the image view.

To make it less jarring, you could quickly fade the image view in and out.

Upvotes: 3

Related Questions