Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change background for UIWebView in iOS

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]; } 
like image 774
leon Avatar asked Oct 10 '09 05:10

leon


People also ask

How do I change the background of my view controller?

First let us see using storyboard, Open Main. storyboard and add one view to the View Controller. On the right pane you can see the property, and from there update the background color to color you want your view to be as show below. Now let us see how we can change the color programmatically.

How do I change the background in Xcode?

At the top select the attributes inspector. Under the section "View" there should be a spot that says "Background". click that and choose your colour.

How do I change the background color in Viewcontroller?

Find the view or view controller you want to change the background color of. Open it up in the interface builder and open the Attributes Inspector. Find the background color field and set it to the color you want.


1 Answers

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

[webView setOpaque:NO]; 
like image 102
Kaveh Avatar answered Sep 19 '22 13:09

Kaveh