tableView单元格左边是白色
问题描述:
我创建了一个tableView,我试图给它一个backgroundColor,但突然发生了一个奇怪的行为。左侧是白色,而不是我给它的背景颜色?这是什么原因?tableView单元格左边是白色
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.backgroundColor = UIColor(rgba: "#333843")
cell.textLabel?.font = UIFont(name: "HelveticaNeue", size: 16)
cell.textLabel?.text = "Favoritter"
cell.textLabel?.textColor = UIColor(rgba: "#ffef7c")
return cell
}
答
要应用的文本标签上的彩色背景。
所以,如果你想改变单元格的背景,你应该这样做:
cell.backgroundColor = UIColor(rgba: "#333843")
+1
wooooow。我怎么可能如此盲目。有几个小时看这个... – 2014-10-16 15:34:18
+0
我的答案是否解决了这个问题?如果没有,你可以检查你的故事板或你的xib文件,单元格可能不会占用他所有的容器大小。 – Pintouch 2014-10-16 15:54:46
答
应用背景颜色为内容查看。
cell.contentView.backgroundColor = UIColor(rgba: "#333843")
尝试更改inset = 0或将单元格背景颜色更改为您当前的背景颜色。 – Bejibun 2014-10-16 15:30:34