conorgriffin
conorgriffin

Reputation: 4339

How do I set the background of UITableViewCell appropriately?

I've set the colour of my UITableViewCell as follows:

UIColor *RedCell = [UIColor colorWithRed:(199/255.0)  green:(0/255.0)  blue:(39/255.0)  alpha:0.2];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = RedCell;

However, you can see in the screenshot that it is creeping outside the border of the cell. What's the appropriate way to set the background so this doesn't happen?

UITableViewCell

Upvotes: 0

Views: 45

Answers (2)

katzenhut
katzenhut

Reputation: 1742

try cell.backgroundColor, as per the docs

http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1

You shouldnt modify the contentView, exceptz to add subviews to it. For a full understanding of how TableViews work, read the provided link. Trust me, it is worth your time.

Upvotes: 0

borrrden
borrrden

Reputation: 33421

For grouped tableview cells, you should set the background color on the background view, instead of the content view (which I assume is a clear background).

Upvotes: 2

Related Questions