RexOnRoids RexOnRoids - 2 months ago 20
Objective-C Question

How to control the color of a UIWebView (before contents load)?

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.

Answer

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.