I'm working on an app in which I load different html files with mostly dark backgrounds. Right now there's a small white flash when navigating from one page to another, presumably since the next page has not loaded yet. I'd like to get rid of that flash and thought the most straightforward way would be to give the WebView a background color.
I tried setting the color for the WebView as well as the scrollView inside of it, but that doesn't seem to work:
self.webView?.backgroundColor = UIColor.blackColor()
self.webView?.scrollView.backgroundColor = UIColor.blackColor()
I see a flash of the color when the view is loaded the first time, but not on subsequent navigation.
To stop 'white flash' on your dark background, do this
webView.opaque = false
This doesn't really solve background colour issue, but at least it stops 'white flash' you are experiencing. Apparently there seem to be no way to change background colour of WKWebView before loading HTML on it.
Swift 4
webView.isOpaque = false