How to customize the background color of a UITableViewCell?
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIColor *color = ((indexPath.row % 2) == 0) ? [UIColor colorWithRed:255.0/255 green:255.0/255 blue:145.0/255 alpha:1] : [UIColor clearColor];
cell.backgroundColor = color;
}
本文介绍了一个简单的自定义UITableViewCell背景颜色的方法。通过实现tableView:willDisplayCell:forRowAtIndexPath:方法,根据单元格的位置来改变其背景颜色,实现了交错的颜色效果。

被折叠的 条评论
为什么被折叠?



