I have a NSOutlienView. I use standard background color for selected rows (according to docs this is NSColor.alternateSelectedControlColor and NSColor.secondarySelectedControlColor).
I subclass NSTableRowview and I change the color of a label based on the current state. Something like this (ignore bad code formatting, can't format on these forums):
NSColor *labelColor;
//White if the window is key and app is active, otherwise black for the label because the white text on light gray highlight doesn't look good.
if (self.window.isKeyWindow
&& NSApp.isActive && self.amISelected)
{
labelColor = [NSColor whiteColor];
}
else
{
labelColor = [NSColor blackColor];
}
self.theLabel.textColor = labelColor;
The problem with this is my outline view can go hidden and come back. And when the outline view unhides, the selected row background color goes light gray even though the app is active and the window is key, so my label draws white text on the light gray background. I haven't been able to find a way around this. I'd imagine I'd be able to workaround this if there was a way to do something like this,
//just sniff the selected color to determine what text color to use...
if ([self.enclosingOutlineView.currentSelectedRowColor isEqual:NSColor.secondarySelectedControlColor])
{
//do whatever
}
else
{
//do whatever
}
But I don't see a way to do this? Sometimes I can workaround the problem by forcing the outline view to be first responder after it unhides and the selection color goes blue, but that's not great and doesn't always seem to work.