Take the 2-minute tour ×

I have to set the backgroundColor property of a UITableView to a certain color in my universal app. If I write this...

self.tableView.backgroundColor = [UIColor colorWithRed:146.0f green:197.0f blue:240.0f alpha:1.0f];

...it doesn't work on iPhone nor iPad (background results white).

If I use a standard color, instead...

self.tableView.backgroundColor = [UIColor greenColor];

...it works on iPhone but not on iPad.

I tried other solutions suggested on SO (backgroundView to nil/clearColor, etc.), but none of those works on iOS SDK 5. Can you help me?

share|improve this question
Your RGB values should be between 0.0f and 1.0f. See this similar question. –  Ben Challenor Dec 1 '11 at 10:42
I am having the same issue. For iPad with iOS 5.0, it looks like the background color of tableview cannot be changed. Please post the answer if you were able to fix the issue. –  calampunay Apr 24 '13 at 14:49
add comment

3 Answers

You need to divide each color value to 255. Your color will be:

[UIColor colorWithRed:146/255.0 green:197/255.0 blue:240/255.0 alpha:1.0];
share|improve this answer
add comment

Instead of changing the background color, you can set a backgroundView (with the background color that you like) for the tableView.

UIView *bgView = [[UIView alloc] initWithFrame:self.tableView.bounds];
bgView.backgroundColor = [UIColor redColor];
self.tableView.backgroundView = bgView;
share|improve this answer
add comment

Are you using a navigation controller?

Try this:

 self.tableView.backgroundColor = [UIColor clearColor];
[self.tableView setSeparatorColor:[UIColor clearColor]];
self.navigationController.view.backgroundColor = [UIColor greenColor];

Thats what I use with iOS5 and an universal app.

share|improve this answer
OK. I got a minus. And I understand that my answer is just half the answer because you should indeed divide the numbers with 255. But the problem with the iPad is also to set the tableview background to clearColor because it works differently on the iPad compared to the iPhone. That the explanation why [UIColor greenColor] works on the iPhone and not on the iPad. –  Chrizzz Mar 20 '12 at 21:55
add comment

Your Answer


