views:

216

answers:

2

Hi,

I'm trying to build a native application that for all intents and purposes is HTML/CSS and Javascript. It all works fine, but when the UIWebView loads there's a delay while the DOM is populated, images retrieved etc.

Is there anyway to display a background image on the UIWebView, or something behind it? Ideally this will be the same as the splash screen so it doesn't affect the experience of transitioning from slash to app.

Thanks

Robbie

+1  A: 

I've had to do the following in my code to get a transparent background on my UIWebViews - I usually do this in the viewDidLoad method of the UIViewController

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

I think you can also make those changes in Interface Builder in the UIWebViews properties.

--- edit ---

And for the background image you can just put a UIImageView in behind the UIWebView now that you've given it a transparent background.

rickerbh
iOS4 gives all views a new property of .backgroundView which removes the need for setting .backgroundColor to clearColor and then putting an image behind it. However I don't agree that adding a background image (which the web page will gradually load *on top* of) is the right approach here...
h4xxr
So that certainly works, I had some issues with loading from different landscapes but that's something I need to learn anyway.
Robbie
+2  A: 

I don't believe you want to be setting the UIWebView as transparent and showing an image behind it.

Instead you should have some sort of view (maybe with a picture as you suggest, maybe with a UIIndicator and a semi-transparent view that "darkens" the page) that sits there until the UIWebView has loaded its content.

To do this, first your class should subscribe to the UIWebViewDelegate protocol:

@interface myWebView : UIViewController <UIWebViewDelegate> {
  // variables etc
}

Then, you can show a view on load:

-(void)viewDidLoad {
  myView.hidden = NO;
}

And finally, you can override the webViewDidFinishLoad method to hide it once it's loaded

- (void)webViewDidFinishLoad:(UIWebView *)localwebView {
    myView.hidden = YES;
}
h4xxr
Do the appropriate events get fired for something like the UIWebView upon loading and rendering the HTML and CSS? Something like the $(document).ready() equivalent from jQuery? I'll definitely give this a try, thanks.
Robbie
Yes, the jQuery equivalent is a good comparison.
h4xxr