ios - 为我的 UITableViewCell 设置背景颜色不起作用

标签 ios uitableview background-color

我有一个带有 TableView 的 View ,以编程方式创建(没有 XIB 关联)。我希望某些单元格具有浅灰色背景色。 所以我尝试了这个:

cell.contentView.backgroundColor = [UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0];

但这是结果(问题当然是单元格的背景应该完全是灰色的):

enter image description here

我也试过了,结果和之前一样:

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];

似乎没有任何效果。感谢您的帮助。

最佳答案

设置tableviews的背景色为clear color。

 tableView.backgroundColor = [UIColor clearColor];

关于ios - 为我的 UITableViewCell 设置背景颜色不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16940046/

相关文章:

ios - 当 Realm 上的对象失效时该怎么办

iOS TableView 不显示数据(调用委托(delegate))

iphone - 如何更改圆角矩形 UIbutton 背景颜色

jquery - 如果在其他地方单击,则更改背景颜色

html - DataTables 隐藏/显示隐藏列按钮 CSS 样式

ios - 在 UITableViewCell 上单击附件时运行方法

iphone - 设备锁定时响应事件

iphone - 在 localizable.strings 中添加富文本

ios - 如何向单元格添加通话按钮

ios - 使用来自不同函数的 tableviewcell