问题描述
||
我想为表格视图单元格提供其他颜色。例如,第一个单元格颜色保持白色,而下一个单元格为浅灰色,然后第三个单元格再次为白色,然后下一个单元格再次为浅灰色,依此类推。有人可以告诉我该方法吗。
谢谢,
克里斯蒂
解决方法
在您的“ 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];
}