MyTableCell *cell=[[MyTableCell alloc]init];
cell.backgroundColor = [UIColor clearColor];
上面的代码行仍然显示单元格背景的白色并隐藏了tableview的背景图像。
转到你的故事板,并设置你的uitableview单元格的颜色,从那里清除颜色。并设置uitabelview颜色也清除颜色。
或者在viewdidload中设置tableview背景颜色以清除颜色,并在indexparth delagate中设置cellforrow
cell.contentView.backGroundColor = [UIColor ClearColor]
试试这个
- (void)tableView:(UITableView *)tableView willDisplayCell(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setBackgroundColor:[UIColor clearColor]];
}
同时设置contentview背景颜色
cell.contentView.backGroundColor = [UIColor ClearColor];
cell.backGroundView.backGroundColor = [UIColor ClearColor];
cell.selectedBackGroundView.backGroundColor = [UIColor ClearColor];
还要检查你是否也清除了tableView.backGroundColor
谢谢大家。我已经解决了这个问题。我将故事板中属性检查器中的背景属性从我的单元格对象从默认更改为清除颜色并且工作正常。
你可以这样做
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView.backgroundColor = [UIColor clearColor];