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

问题描述

|| 我想为表格视图单元格提供其他颜色。例如,第一个单元格颜色保持白色,而下一个单元格为浅灰色,然后第三个单元格再次为白色,然后下一个单元格再次为浅灰色,依此类推。有人可以告诉我该方法吗。 谢谢, 克里斯蒂     

解决方法

        在您的“ 0”数据源方法中插入以下测试:
NSUinteger row=indexPath.row;
if (row % 2==0)
 cell.contentView.backGroundColor=[UIColor blueClor] ;
else
 cell.contentView.backGroundColor=[UIColor whiteClor] ;
    ,        使用这个克里斯蒂:
- (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;
    }
}
    ,        克里斯蒂娜(Hii Christina): 看一下这个,
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if ((indexPath.row % 2) == 0) {

    cell.backgroundColor = [UIColor whiteColor];

            }
    else {

    cell.backgroundColor = [UIColor lightgrayColor];
        }
}
希望这可以帮助!     ,        试试这个克里斯蒂(Christy):
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{
cell.backgroundColor = indexPath.row % 2 ? [UIColor lightGrayColor] : [UIColor whiteColor];
}
    ,        创建ѭ5时,请使用以下代码。
if(indexPath.row % 2 == 0)
{
    myCell.backgroundColor = [UIColor whiteColor];
}
else if(indexPath.row % 2 == 1)
{
    myCell.backgroundColor = [UIColor grayColor];
}
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...