选中时设置单元格backgroundColor - Swift

时间:2014-06-22 17:50:55

标签: colors swift cell

在stackOverflow上,我找到了一种方法,允许iOS用户更新默认"已选择" tableCell的颜色。 现在,如何在OS X上使用Swift做同样的事情?

适用于iOS的代码:

var bgColorView = UIView()
bgColorView.backgroundColor = UIColor.redColor()
cell.setSelectedBackgroundView = bgColorView

我尝试更改OS X用途的代码。没有成功

//Set selected color of cell
    var bgColorView = NSView()
    bgColorView.backgroundColor = NSColor.redColor()
    cell.setSelectedBackgroundView = bgColorView

这是我得到的错误 Errors image

谢谢大家。阿尔贝托。

2 个答案:

答案 0 :(得分:0)

var myBackView = UIView(frame:cell.frame)

myBackView.backgroundColor = UIColor.redColor();

cell.selectedBackgroundView = myBackView;

答案 1 :(得分:0)

试试这个:

cell.backgroundColor = UIColor.YellowColor()

此行在cellForRowAtIndexPath

之后