To change the background color of the cell, you have to do it in the willDisplayCell:forRowAtIndexPath:
method. This is mentioned in the UITableViewCell documentation near the bottom of the Overview. So you need:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor redColor];
}
The contentView is just the recommended subview to put custom controls in so that the cell gets layed out properly when table editing is going on.
There's an easier solution: When you create a UITableViewCell
in Interface Builder, simply drag and drop an additional UIView
so that it covers the entire UITableViewCell
you're creating within IB. Place your additional UI elements on top of this additional UIView
. You can set this extra UIView
to whatever background you like.
There are quite a few answers on StackOverflow that suggest you change the background color of your UITableViewCell
by using a line of code like this one:
cell.contentView.backgroundColor = [UIColor redColor];
If you add a drop shadow to your cell by adjusting the contentView
's frame size slightly, you may find that this line will change both the background color of your cell and the color of your drop shadow area as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With