gpt4 book ai didi

ios - 无法以编程方式设置单元格容器 BG

转载 作者:行者123 更新时间:2023-11-29 01:02:34 27 4
gpt4 key购买 nike

我有一个像 BasicCell>ContentView>Container 这样的 UITableView 单元设置。当我在界面生成器中设置容器的背景时,我得到了我设置的所需的深灰色阴影。但是,当我以编程方式设置较暗的阴影时,在 cellForRowAtIndexPath 中,我得到了白色背景。

cell.container.backgroundColor = UIColor(red: 20, green: 20, blue: 20, alpha: 1.0)

因此,通过引入程序化颜色设置,它突然忽略了界面构建器颜色和程序化颜色。我已经阅读了几个主题并尝试过使用 willDisplay 单元格之类的东西:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let myCell = cell as! CustomTableViewCell_F2
myCell.backgroundColor = UIColor.clearColor()
myCell.backgroundView = nil
myCell.container.backgroundColor = UIColor(red: 20, green: 20, blue: 20, alpha: 1.0)
}

我也试过在 CustomTableCell 类中设置它。那没有用。发生了什么,我该如何解决?

最佳答案

改变

cell.container.backgroundColor = UIColor(red: 20, green: 20, blue: 20, alpha: 1.0)

let shade: CGFloat = 0.2
cell.container.backgroundColor = UIColor(white: shade, alpha: 1.0)

你的颜色UIColor(red: 20, green: 20, blue: 20, alpha: 1.0)实际上是白色。您应该提供 0.0 到 1.0 范围内的颜色分量值。

关于ios - 无法以编程方式设置单元格容器 BG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36842373/

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