如何解决在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];
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。