I am trying to change my UITableView from being all white to have a black background, but how can I achieve this in the Interface Builder?
Asked
Active
Viewed 944 times
1 Answers
0
According to Apple...
... In iOS 7, cells have a white background by default; in earlier versions of iOS, cells inherit the background color of the enclosing table view. If you want to change the background color of a cell, do so in the tableView:willDisplayCell:forRowAtIndexPath: method of your table view delegate.
So to do it in code, its very simple...
First, go ahead and add this to your viewDidLoad in your tableViewController:
UIView *patternView = [[UIView alloc] initWithFrame:self.tableView.frame];
patternView.backgroundColor = [UIColor blackColor];
patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.backgroundView = patternView;
And then in your cellForRowAtIndexPath, Add this:
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor whiteColor];
(The textLabel can be any color you want)
Also refer to this:UITableViewCell show white background and cannot be modified on iOS7
There seems to be a bug when you do it in Interface Builder.

Community
- 1
- 1

Steve Sahayadarlin
- 1,164
- 3
- 15
- 32
-
I think it should be time for me to learn how to code without interface builder.... – preston320 Jun 30 '14 at 12:53
-
Well, it depends on how much you want to customize something. IB is ok for little customization, but code has much more specific options. Did you try adding my code into your project? – Steve Sahayadarlin Jun 30 '14 at 16:18
-
yeah i tried it. it worked for me – preston320 Jul 15 '14 at 19:44