这很简单。我已经在 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 测试版
最佳答案
你应该设置:
cell.backgroundColor = .clear
你还应该为整个 tableView 提供清晰的颜色:
tableView.backgroundColor = .clear
我已经在示例项目中进行了测试。我用 UITableView
创建了 UIViewController
。为 UIViewController
的 view
设置 .red
颜色。创建 UITableView
,为 cell
和 tableView
应用 .clear
颜色。您应该看到红色背景 - 因此单元格和 tableView 是透明的。
这是示例屏幕(标签添加到 UIViewController
的 .view
以确保 tableView
是透明的):
关于ios - 无法使 UITableViewCell 具有清晰的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40577849/