Adding a fixed image background to UIWebView

A short post for iOS people.

UIWebView doesn’t (as of iOS 5.0) honor background-attachment: fixed; in CSS, so if you need a fixed background image on a UIWebView, you’re probably searching Google trying to find the answer.

Hopefully, this will help.

UIWebView *someWebView;
someWebView.opaque = NO;
someWebView.backgroundColor = [UIColor clearColor];

UIImageView *imageView;
imageView.image = [UIImage imageNamed:@”something”];
imageView.autoresizingMask = (UIViewAutoresizingFlexibleHeightUIViewAutoresizingFlexibleWidth);
imageView.contentMode = UIViewContentModeScaleToFill;
imageView.frame = someWebView.bounds;
[someWebView insertSubview:imageView atIndex:0];

One response to “Adding a fixed image background to UIWebView”

  1. Thanks, that was helpful!

    Like

Leave a Reply to Anonymous Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: