Search code examples
macoscolorsnstableviewnscolor

What's the selection highlight color of an NSTableView?


I'm making a completely custom control (NSView), and I want to use the user's preferred highlight color for part of it when it's selected, like NSTableView does.

Unfortunately, there doesn't seem to be any way to get this. The NSColor documentation only lists one (non-deprecated) user-chosen color, selectedTextBackgroundColor, and NSTableView uses a much darker or more saturated (?) color for the selection highlight.

I've tried a couple things, like turning up the saturation (fails for gray), and darkening with shadow() (looks bad, and not like NSTableView), but I'm not an expert on colors.

Does anybody know what NSTableView is doing, to get this color? Is there any way to access it more directly?


Solution

  • NSColor.alternateSelectedControlColor is what you want. The comments in NSTableView.h are somewhat out of date (referring to the color being light blue, when it isn't any more). I don't see the constants in NSColor being deprecated... not sure what you are talking about? (Maybe a documentation bug? When in doubt, look at the headers...)