如果其他人仍然在 iPad 上的表格视图/单元格透明度方面遇到问题,这可能会有所帮助(从https://stackoverflow.com/a/31396483/2301213复制,自从他们改变的时候就很快了)
似乎在向窗口添加 UITableView 的过程中(在 willMoveToWindow 和 didMoveToWindow 之间),某些 iPad 将 table view 的 backgroundColor 重置为白色。它在不使用 backgroundColor 属性的情况下秘密地执行此操作。
当我需要彩色/透明表格时,我现在将其用作 UITableView 的基类...
class ColorableTableView : UITableView {
var _backgroundColor:UIColor?
override var backgroundColor:UIColor? {
didSet {
_backgroundColor = backgroundColor
}
}
override func didMoveToWindow() {
backgroundColor = _backgroundColor
super.didMoveToWindow()
}
}
单元格的背景颜色在我的 iPad 上也以相同的方式设置为白色(即在移动到窗口期间位于表格中的单元格),因此这同样适用于它们,以免最终出现奇怪的不透明单元格从不时重复使用...
class ColorableTableViewCell : UITableViewCell {
var _backgroundColor:UIColor?
override var backgroundColor:UIColor? {
didSet {
_backgroundColor = backgroundColor
}
}
override func didMoveToWindow() {
backgroundColor = _backgroundColor
super.didMoveToWindow()
}
}