I am trying to have a BLACK colored UIWebView before its contents load. In IB, i tried both making the background color of the UIWebView black, as well as, making it have a transparent background and have its parent view's background be black. Both don't work. When my UIWebView loads the background of it is white. How can I fix this?
*I hope this does not boil down to having to load an html string first (before loading my actual web content) to set the background to black vis CSS.
Actually setting the background color cannot make the web view entire black. The content of a web page is presented in a subview within the web view, a web view contains many undocumented subviews, including a UIScrollView which allows you to scroll the contents, and a UIScrollView contains UIWebDocumentView, which draws the web contents. They are above the background of your web view, so they cover the background, what you can see is the UIWebDocumentView and setting the background color cannot make your web view entire black.
I guess the solution is, you may try to place a black view over your web view, and hide the view when the delegate methods such as webViewDidFinishLoad:
or webViewDidStartLoad:
are called.
The way I did this was to put the UIWebView on a black colored view. Then, we set the web page and the webview to be clear. Works in iOS 4.2 .
On the superview:
view.backgroundColor = [UIColor blackColor];
On the webView:
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
In the Web HTML:
<body style="background-color:transparent;">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With