Eric
Eric

Reputation: 2018

Dark Mode: NSColor.colorNamed doesn't return the right color in certain methods

colorNamed generally works for me, however, I am trying to call it inside NSTableViewRow.drawSeparatorInRect:, and it always return the color in the light appearance, even if the system is in Dark Mode.

- (void)drawSeparatorInRect:(NSRect)dirtyRect { [[NSColor colorNamed:@"ColorTransactionsGridLine"] set]; ... }

I can't figure out why colorNamed doesn't work in this case. Any ideas?

Thanks.

Upvotes: 2

Views: 841

Answers (2)

Eric
Eric

Reputation: 2018

I figured this one out. Turns out the parent view has appearance hard coded, so the subview inherit that appearance rather than the system's. After changing appearance to "inherit" in the parent view(s), colorNamed returns the right color.

Upvotes: 1

pointum
pointum

Reputation: 3177

Try adding this before your drawing code:

 NSAppearance.currentAppearance = self.effectiveAppearance;

Or, as a diagnostic measure, set a breakpoint in your drawing code and check the status of these properties in the debugger.

Upvotes: 1

Related Questions