[NSColor highlightColor] differs in dark mode

I noticed a point today while working on dark mode for Mojave 10.14.

The value of -(NSColor*)highlightColor differs depending on whether you’re in light mode or dark mode.

This particularly affects -(NSColor *)highlightWithLevel:(CGFloat)val;

By calling:

[[NSColor highlightColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];

I was able to grab the highlight colors in light mode and dark mode. I converted the values to hex and they are displayed below:

Light Mode:


Dark Mode:



Highlight color is noted as for “The virtual light source onscreen”, but it is occasionally suggested for providing slight variations on a drawing color.

Which is great, except that because the output differs between light mode and dark mode, you can’t now use it anywhere within a drawn document unless you want things to look different between the two display appearances.

In the end I replaced the method call with this new code:

NSColor* color = [NSColor redColor];
CGFloat fraction = 0.7;
NSColor* newColor = [aColor blendedColorWithFraction:fraction 
   ofColor:[NSColor colorWithCalibratedWhite:1 alpha:1]];

I also produced a roughly equivalent swift version:

import Cocoa

let color = NSColor.red;
let fraction = 0.7 as CGFloat;
let newColor = color.blended(withFraction: fraction, of: NSColor.init(calibratedWhite: 1, alpha: 1));

print(newColor?.description ?? "invalid color");


See https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/color/


This entry was posted in Macintosh, Writing Software. Bookmark the permalink.