如何更改tableview顶部和底部的背景颜色?

时间:2011-11-29 21:37:24

标签: iphone uitableview

我更改了tableview单元格颜色。但是当我向桌面的上方或下方移动时,它仍然是白色的。如何以编程方式更改空白颜色?

2 个答案:

答案 0 :(得分:1)

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

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

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

这是一个比简单地说cell.backgroundColor = desiredColor更好的解决方案,因为如果您决定使用视图(例如图案)而不仅仅是颜色作为表格的背景,那么背景将在所有时间,而不仅仅是当您反弹内容时。

答案 1 :(得分:0)

tableView.backgroundColor = [UIColor yellowColor]