Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Background colour on NSTableCellView

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!

like image 632
Gareth Jeanne Avatar asked Jul 22 '13 18:07

Gareth Jeanne


2 Answers

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
like image 166
Caleb Avatar answered Sep 22 '22 23:09

Caleb


You need to convert your NSColor object into a CGColor struct:

self.layer.backgroundColor = [[NSColor redColor] CGColor];
like image 40
c9s Avatar answered Sep 18 '22 23:09

c9s