aherlambang
aherlambang

Reputation: 14418

changing UITableViewCell background

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

Upvotes: 6

Views: 7004

Answers (3)

Jake Dahl
Jake Dahl

Reputation: 169

//in willDisplayCell
if (indexPath.section > 0) {
    cell.backgroundColor = [UIColor blueColor];
}

Upvotes: -3

Alex Nguyen
Alex Nguyen

Reputation: 2820

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

Upvotes: 0

conmulligan
conmulligan

Reputation: 7148

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];
}

Upvotes: 13

Related Questions