Reputation: 1420
I am trying to set a background colour on an NSTableCellView, but there doesn't seem to be an way to do this.
Therefor there must be another way to achieve this that i am not aware of, so, if anyone could enlighten me i would be most appreciative!
Thanks!
Upvotes: 5
Views: 5048
Reputation: 7778
for Swift 3, and based on Caleb's answer, this works for me:
cell.wantsLayer = true
cell.layer?.backgroundColor = NSColor.red.cgColor
It took me ages to find this question and answer, and I'm most appreciative.
Upvotes: 1
Reputation: 124997
A NSTableCellView
is a NSView
, and a NSView
has a CALayer
, and a CALayer
has a backgroundColor
. So...
myTableCellView.wantsLayer = YES; // make the cell layer-backed
myTableCellView.layer.backgroundColor = [[NSColor redColor] CGColor]; // or whatever color you like
Upvotes: 12
Reputation: 1917
You need to convert your NSColor object into a CGColor struct:
self.layer.backgroundColor = [[NSColor redColor] CGColor];
Upvotes: 1