Skip to content

How to get alternate background color for UITableViewCell in Xcode

by paddoum on February 3rd, 2010

I found a very efficient way to do it :





- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
 cell.backgroundColor = (indexPath.row%2)?[UIColor grayColor]:[UIColor clearColor];
 }

I also recommend Olivier Drobnik snippet to solve the following dilemma : “How can I make my cells alternate colors across multiple sections if the sections don’t always have the same number of rows?”

From → Tutorial

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS