How to set background color for UIWebView in iPhone sdk

I added a back color as the image in uiwebview, but it goes to the back of the web view, not the web view. Web browsing is always displayed in white, I cannot 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 set the background color for web viewing not for him.

+6
colors iphone background uiwebview
source share
3 answers

[webView setOpaque: NO];

+46
source share

Web browsing will display the document, so the background color really doesn’t make much sense here. If you want to display something while the page is not loading, create a placeholder page containing your background.

+3
source share

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

 - (void)webViewDidFinishLoad:(UIWebView *)webView 

If you need to set the background color in the UIWebView after loading the content, you will do this in the HTML / CSS markup:

 "background-color: #026dec;" 
+1
source share

All Articles