Change UIWebView's color while loading content

1.2k Views Asked by At

I have a UIWebView in my app that shows some html-formatted text (loaded from a .plist file from my bundle). The UIWebView takes about 1 second to render the text on the screen and during that second the whole UIWebView is white. I have tried setting the backgronud color of the view to clear or black but that did not do anything. I also tried using the delegate methods to show the UIWebView only when it didLoadContent but that method is never called since there us no request involved, I'm only rendering an html string there.

Is there a way to show nothing until the view is rendered?

If not, is there another way to render html-text on an iPhone?

Thank you.

3

There are 3 best solutions below

0
On

I handle this in my app with a javascript variable that I check with a NSTimer that is fired every 0.5 seconds... I leave the view hidden until that variable is set...

1
On

Off the top of my mind: Set the UIWebView's hidden property to YES, display something call a selector to change the hidden property to NO in 2-3 seconds.

BTW do you mean you're loading a local HTML file? Or is the delay created by downloading the file?

~ Natanavra.

1
On

You said this HTML was loaded and presented "while app loads" which I guess means starting up instead of loading some other data from somewhere? I'm also guessing the HTML is fully static hardcoded data, since you load it "offline" from .plist...

Suggestion: why don't you take a screenshot of the ready-rendered page, save that inside your app and display during app startup? Should be faster.