1

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?

preston320
  • 113
  • 5

1 Answers1

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,150
  • 3
  • 15
  • 31