0

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

2
  • Try setting the background color on the cell's background view instead of its content view Commented Feb 19, 2013 at 9:47
  • Yup, that did it! Stick this in an answer and earn yourself some points Commented Feb 19, 2013 at 9:51

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

1 Comment

this works well, although apple suggests otherwise. See my answer. The reason behind this is that they may change th internal structure of cells in the future, but cell.backgroundcolor will always be supported.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.