Can't change background for UIWebView in iOS

Viewed 35720

Is there a way to change background color for UIWebView?

None of the colors set in IB effect UIWebView behavior: before actual content is loaded it shows as up as white (causing a white flash between the moment it is loaded and content is rendered).

Setting background color programmatically does not do anything either.

Here is code:

@interface Web_ViewViewController : UIViewController {

    UIWebView *web;
}

@property (nonatomic, retain) IBOutlet UIWebView *web;
@end

....
-(void)viewDidLoad {
    super viewDidLoad;

    web.backgroundColor = [UIColor blueColor];
    NSURL *clUrl = [NSURL URLWithString:@"http://www.apple.com"];
    NSURLRequest *req = [NSURLRequest requestWithURL:clUrl];

    [web loadRequest:req];
}
8 Answers

You can set the opaque property of the webview to NO and then set background color of the view beneath.

[webView setOpaque:NO];

I got a solution. Add the web view after it is loaded.

-(void)webViewDidFinishLoad: (UIWebView *)pageView {

    self.view =pageView;
    [pageView release];
}
Related