我有一个自定义表格 View 单元格。单元格内部是我从对象库添加的标签,我给它的 viewWithTag
值为 1。表格 View 单元格中的标签具有黄色背景色。这是代码:
在 cellForRowAtIndexPath
我有
let label = cell.viewWithTag(1) as! UILabel
label.backgroundColor = yellowColor // yellowColor is a regular UIColor I defined elsewhere
println(label.backgroundColor) // returns Optional(UIDeviceRGBColorSpace 0.980392 0.776471 0 1)
现在,在 prepareForSegue
我有
let cell = tableView.cellForRowAtIndexPath(tableView.indexPathForSelectedRow()!)
let labelBackgroundColor = cell?.viewWithTag(1) as! UILabel).backgroundColor
println(labelBackgroundColor) // returns Optional(UIDeviceWhiteColorSpace 0 0)
因此,根据我的理解,我从同一标签的 backgroundColor 属性中获取 Optional(UIDeviceRGBColorSpace 0.980392 0.776471 0 1)
和 Optional(UIDeviceWhiteColorSpace 0 0)
。它不应该是相同的RGB值吗?我在这里错过了什么?如果这是访问标签的 backgroundColor 属性的错误方法,我将如何正确访问它?
最佳答案
这似乎是由于选择时发生的颜色变化。如果您将单元格的选择样式设置为“无”,则会在 prepareForSegue
中报告正确的颜色。
关于ios - cellForRowAtIndexPath 和 prepareForSegue 返回不同的标签颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30720241/