Search code examples
ioscocoa-touch

How to prevent initial white flash when showing a UIWebView?


I use a UIWebView to show an "About" screen by displaying a bundled HTML file. My app's view hierarchy is: UITabBarController / UIViewController / UIWebView.

The problem is that the HTML page has a dark background, and the very first time the tab is tapped, a white background is visible briefly before the web view is displayed. I tried setting the background color of the UIWebView, but that doesn't solve the problem. The problem occurs whether I load the content in viewDidLoad or viewWillAppear.


Solution

  • Swift:

    webView.isOpaque = false
    webView.backgroundColor = UIColor.clear
    

    Objective-C:

    webView.opaque = NO;
    webView.backgroundColor = [UIColor clearColor];