6

I know this might have been asked thousands time, I tried changing the background for my UITablewViewCell via the following:

 cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];
              cell.textLabel.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];

and all I have now is:

enter image description here

How do I set that accessory view background view color as well?

UPDATE: I have a section header on top in which it has a white background

aherlambang
  • 14,290
  • 50
  • 150
  • 253

3 Answers3

13

Put this in your UITableViewDelegate:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];
}
conmulligan
  • 7,038
  • 6
  • 33
  • 44
0

You're over-complicating it a bit. You can just change the tableview's background color which does exactly what you want. This way, you don't have to set the color for EVERY cell. :)

    self.tableView.backgroundColor = [UIColor greenColor];
Alex Nguyen
  • 2,820
  • 1
  • 19
  • 14
-3
//in willDisplayCell
if (indexPath.section > 0) {
    cell.backgroundColor = [UIColor blueColor];
}
Jake Dahl
  • 171
  • 2
  • 3
  • 13