UIWebView Background Color


 

UIWebView Background Color

If you wanted to change the background color on UIWebView in iPhone SDK, then you required to set the background color of UIWebView using UIColor.

If you wanted to change the background color on UIWebView in iPhone SDK, then you required to set the background color of UIWebView using UIColor.

UIWebView Background Color

If you wanted to change the background color on UIWebView in iPhone SDK, then you required to set the background color of UIWebView using UIColor. UIColor object represents color and opacity (alpha value). Where as setBackgroundColor will allow you to change the color of background area of UIWebView or UIView.

This example illustrate you how to change the color of UIWebView in iPhone SDK based application. To change the color of background first we need to set the backgroundcolor as clearColor and then set the required color to it as given in the following code.

- (void)viewDidLoad {
[super viewDidLoad];

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]];

//Set the UIWebView background color and opaque:NO
[webView setBackgroundColor:[UIColor clearColor]];
[webView setBackgroundColor:[UIColor purpleColor]];

[webView setOpaque:NO];

}

On running the application you'll find the output similar to give image.

Download Code

Ads