Ios 将背景色设置为my UITableViewCell赢得';行不通
我有一个带有表视图的视图,是通过编程创建的(没有与XIB关联)。我希望一些单元格的背景颜色为浅灰色。 所以我试了一下:Ios 将背景色设置为my UITableViewCell赢得';行不通,ios,uitableview,background-color,Ios,Uitableview,Background Color,我有一个带有表视图的视图,是通过编程创建的(没有与XIB关联)。我希望一些单元格的背景颜色为浅灰色。 所以我试了一下: cell.contentView.backgroundColor = [UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0]; 但结果是(问题当然是单元格的背景应该是完全灰色的): 我也试过了,结果和之前一样: UIView *cell_view = [[UIView a
cell.contentView.backgroundColor = [UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0];
但结果是(问题当然是单元格的背景应该是完全灰色的):
我也试过了,结果和之前一样:
UIView *cell_view = [[UIView alloc] init];
[cell_view setBackgroundColor:[UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0]];
[cell setBackgroundView:cell_view];
似乎什么都不管用。谢谢你的帮助。不要给背景颜色。而是创建具有所需颜色的视图。并设置为backgroundView。覆盖
表视图:willDisplayCell:forRowAtIndexPath:
委托:
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0]];
}
另外,将textLabel背景色设置为透明
cell.textLabel.backgroundColor = [UIColor clearColor];
将tableviews背景色设置为“清除颜色”
tableView.backgroundColor = [UIColor clearColor];
请执行以下操作:
//set this in viewDidLoad method
yourTable.backgroundColor = [UIColor clearColor];
//set this in cellForRowAtIndexPath method of UITableView
cell.backgroundview = nil;
cell.backgroundColor = [UIColor greenColor];
这个代码是为我工作的 请尝试以下代码:
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIColor *CellColor = [UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0];
cell.backgroundColor = CellColor;
}已经试过了,但没用(见更新的帖子)。谢谢你的回答。@Rob我很高兴能帮助你:)我试过这个解决方案,但也没用。谢谢您的回答。请尝试使用此单元格。backgroundColor=[UIColor redColor];