Faking A Fixed Background In An iOS Web App

If the lack of a fixed background image position has been bugging you when your building your HTML / CSS based iOS apps, then I thought I’d share a work around I’ve been using.

If you are creating a native app from this in XCode then you would almost certainly be embedding the web page in a UIWebView. This is where the magic works.

Create a UIImageView with your background image on, then place your UIWebView directly over this image.

In your Objective-C you need to set the UIWebView‘s background colour to clearColor and make the UIWebView opaque. If your UIWebView is called webView the following two lines of Objective-C will do this.

[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];

Your background image should now show through the webpage and be visible as the background.