1
votes

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?

3
Your RGB values should be between 0.0f and 1.0f. See this similar question. - Ben Challenor
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. - user2197398

3 Answers

1
votes

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];
0
votes

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;
-1
votes

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.