如何改变tableview的上下边的背景颜色



我更改了tableview单元格颜色。但当我移动到tableview的上下一侧时,它仍然是白色的。如何通过编程方式改变空白区域的颜色?

如果您想要表格和单元格的不同颜色,只需说tableView.backgroundColor = desiredColorUIColor类提供了像+blueColor+redColor等类方法。

如果你想让表格和单元格的颜色相同,保留上面的代码,并将其添加到tableView:cellForRowAtIndexPath:

// Customize the cell
cell.backgroundColor = [UIColor clearColor];
for (UIView *subview in [cell subviews]) {
    subview.backgroundColor = [UIColor clearColor];
}

这是一个比简单地说cell.backgroundColor = desiredColor更好的解决方案,因为如果你决定使用一个视图(比如一个图案),而不仅仅是一个颜色,作为你的表的背景,背景将在任何时候都是可见的,而不仅仅是当你反弹的内容。

tableView.backgroundColor = [UIColor yellowColor]

最新更新