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!


Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: