gpt4 book ai didi

ipad - swift iPad 表格 View 不透明

转载 作者:行者123 更新时间:2023-11-28 11:20:26 25 4
gpt4 key购买 nike

在 swift 中,我有一个 UI 表格 View ,我将背景设置为透明背景,对于 iPhone,它工作得很好。但是对于iPad,它没有,它有一个白色的背景,不清晰。我看到了一个答案,但这不是为了 swift ,但这也没有用。我的 iPhone 代码是:

tableview.backgroundcolor = UIColor.clearcolor()

我尝试添加:

tableview.background = nil 

但这行不通。

最佳答案

我遇到了同样的问题。似乎在向窗口添加 UITableView 的过程中的某个地方(在 willMoveToWindow 和 didMoveToWindow 之间),一些 iPad 将表格 View 的背景颜色重置为白色。它在不使用 backgroundColor 属性的情况下 secret 执行此操作。

当我需要一个彩色/透明表格时,我现在使用它作为基类来代替 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()
}
}

关于ipad - swift iPad 表格 View 不透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28653779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com