我有一个像BasicCell> ContentView> Container一样的UITableView单元设置。当我在界面构建器中设置容器的背景时,我得到了所需的较暗的灰色阴影。但是,当我以编程方式设置较暗的阴影时,在cellForRowAtIndexPath中,我得到一个白色背景。无法以编程方式设置单元容器BG
cell.container.backgroundColor = UIColor(red: 20, green: 20, blue: 20, alpha: 1.0)
因此,通过引入编程颜色设置,它突然忽略了接口构建器颜色和编程颜色。我读过几个线程,并尝试使用willDisplay cell:
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类中设置它。这没有用。发生了什么,我该如何解决它?
试着改变你的tableView的背景颜色。如果此更改将通过单元格可见,请删除'myCell.backgroundColor = UIColor.clearColor()'行。 –
我改变了表BG的颜色,它是可见的。然后,我注释了myCell.background颜色行,仍然是容器视图是白色/很浅的灰色阴影(很难说)。 –