views:

73

answers:

2

How do I fill the background color of a UITableViewCell? I tried this code but it didn't work.

cell.backgroundColor = [UIColor redColor];
A: 

Setting the background color though UITableViewCell's backgroundColor property only works in a Grouped table view. So if your table view is in the Plain style then it won't work.

You can of course set the background color of the UITableView's contentView. But then you probably have to do some additional work as the other subview (text labels and accessory views) have their own idea of background colors.

St3fan
A: 

Try setting a backgroundView for UITableViewCell :

UIView *bgView = [[UIView alloc] init];
bgView.backgroundColor = [UIColor redColor];
cell.backgroundView = bgView;
// release object
[bgView release];

You can change the selection background view of UITableViewCell the same way.

cell.selectedBackgroundView = bgView;
syd
thanks for your code syd
RAGOpoR