I am trying to set the background color in an NSTableCellView, but there seems to be no way to do this.
For this, there must be another way to achieve this, which I do not know about, therefore, if someone could enlighten me, I would be very grateful!
Thanks!
A NSTableCellView is an NSView , and a NSView has a CALayer , and a CALayer has a backgroundColor . So that...
NSTableCellView
NSView
CALayer
backgroundColor
myTableCellView.wantsLayer = YES; // make the cell layer-backed myTableCellView.layer.backgroundColor = [[NSColor redColor] CGColor]; // or whatever color you like
You need to convert your NSColor object to a CGColor structure:
self.layer.backgroundColor = [[NSColor redColor] CGColor];
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 years to find this question and answer, and I am very grateful.
Source: https://habr.com/ru/post/1492766/More articles:Embed rCharts in a slide slide panel - rCreate a list of 2 variables - pythonRebol 3 - How to send username and password via https? - httpssynchronized blocks android - androidHow to create a managed control in WinRT? - windows-8Is a short circuit in nomination statements a good style? - pythonIs blocking or volatility required when worker threads are uncompetitively written to local variables or class variables? - variableshttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1492769/why-is-the-xml-serializer-appending-characters-to-my-xmlattribute&usg=ALkJrhjvggNAKAAKhi6JWRpUk3u_Ttf39gDatatable.WriteXml - How to keep spaces in element names - c #Code mutation tools for Java - javaAll Articles