How to get alternate background color for UITableViewCell in Xcode
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?”
No comments yet