在xcode的表视图中为备用单元格赋予颜色

Chr*_*ina 3 iphone xcode cocoa-touch uitableview ipad

我想为表视图单元格提供替代颜色.例如,第一个单元格颜色保持白色而下一个单元格是浅灰色,然后第三个单元格再次变白,然后接下来又是浅灰色等等.任何人都可以告诉我这样做的方法.

谢谢,克里斯蒂

Sun*_*uny 8

使用这个christy:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (indexPath.row == 0 || indexPath.row%2 == 0) {
        UIColor *altCellColor = [UIColor colorWithRed:100 green:10 blue:10 alpha:1];
        cell.backgroundColor = altCellColor;
    }
}
Run Code Online (Sandbox Code Playgroud)