无法使UITableViewCell具有清晰的颜色

时间:2016-11-13 19:19:55

标签: ios xcode uitableview

这非常简单。我已在tableView:willDisplayCell:forRowAtIndexPath:tableView:CellForRow:atIndexPath:中尝试了几次。

这是我的代码:

cell.alpha = 0.0
cell.backgroundView?.alpha = 0.0
cell.contentView.alpha = 0.0
cell.backgroundView?.backgroundColor = UIColor.clear
cell.backgroundColor = UIColor.clear
cell.contentView.backgroundColor = UIColor.clear

我很确定这应该是矫枉过正,但我​​很难完成这项工作。正在if语句中修改单元格,因为这仅适用于某些单元格。是的,我已经检查过,if语句按预期工作。有什么想法吗?

我正在使用Xcode版本8.2 beta

1 个答案:

答案 0 :(得分:1)

你应该设置:

cell.backgroundColor = .clear

并且你应该为整个tableView提供清晰的颜色:

tableView.backgroundColor = .clear

我在样本项目中进行了测试。我使用UIViewController创建UITableView。为.red的{​​{1}}设置view颜色。创建UIViewController,为UITableView.clear应用cell颜色。您应该看到红色背景 - 因此单元格和tableView是透明的。

以下是示例屏幕(标签已添加到tableView的{​​{1}}以确保.view透明):

enter image description here