Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background color for UIWebView in iPhone sdk

I have added the back ground color as an image to uiwebview but it is coming to the back side of web view not to the web view. The web view is always in white colored view, I can't change it.

myView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
myView.autoresizingMask=YES;

webView = [[UIWebView alloc] init];
webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"BG_Doctor.png"]];

webView.delegate = self;
[myView addSubview:webView];
self.view=myView;

Please help me to set the background color to webview not to back of it

like image 441
Madan Mohan Avatar asked Aug 19 '10 13:08

Madan Mohan


3 Answers

[webView setOpaque:NO];

like image 123
Madan Mohan Avatar answered Oct 19 '22 03:10

Madan Mohan


A webview will display a document, so background color is really nothing that makes a lot of sense here. If you want to display something while no page is loaded, build a placeholder page containing your background.

like image 28
Eiko Avatar answered Oct 19 '22 02:10

Eiko


If you want to display a specific background before the UIWebView has loaded HTML content you can add a loading view over the top and then remove it when you get webViewDidFinishLoad on your UIWebViewDelegate:

- (void)webViewDidFinishLoad:(UIWebView *)webView

If you need to set the background color on the UIWebView once it has loaded the content, then you would do this in the HTML/CSS markup:

"background-color: #026dec;"
like image 33
RedBlueThing Avatar answered Oct 19 '22 02:10

RedBlueThing