LuckyLuke
LuckyLuke

Reputation: 49057

Changing background color on UIScrollView?

How do I change the black/gray color to white?

This is just a simple view with a UIView attached to the UIViewControllers property together a with a webview that fills the UIView.

UPDATE

Here's the code that works:

- (void)loadView {
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 416.0f)];
[webView setBackgroundColor:[UIColor whiteColor]];
self.view = webView;
[webview release];
}

Thanks in advance.

iPhone

Upvotes: 4

Views: 13593

Answers (2)

Andrew Ebling
Andrew Ebling

Reputation: 10283

A few improvements for your code:

- (void)viewDidLoad {
[super viewDidLoad];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(self.view.bounds)];
[webView setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview: webView];
[webview release], webview = nil;
}

Overall you should find this approach less brittle.

PS. If you keep a reference to the UIWebView around, don't forget to release it in - viewDidUnload.

Upvotes: 0

John Parker
John Parker

Reputation: 54425

You can use the UIScrollView's backgroundColor property to achieve this, the signature being:

@property(nonatomic, copy) UIColor *backgroundColor

As such to change it to white, you'd use:

[myScrollView setBackgroundColor:[UIColor whiteColor]];

Upvotes: 11

Related Questions