#StackBounty: #objective-c #cocoa #core-animation #nsview #macos-mojave How to work around transparent system colors when drawing with …

Bounty: 50

With dark mode in macOS 10.14 Mojave, most system colors are semi-transparent. That is to match control colors with the window background, which in turn is slightly tinted to match the desktop picture.

Now when building a view with overlapping CoreAnimation layers, things get messed up. Example:

custom slider control

This is a custom slider built with CALayers. The vertical track is a layer beneath the knob layer. Here’s how I set the colors:

- (void)updateColors // Called from updateLayer()
    self.tickmarkLayer.strokeColor = [NSColor tertiaryLabelColor].CGColor;
    self.tickmarkLayer.lineWidth = 1.0;

    self.trackLayer.backgroundColor = [NSColor controlBackgroundColor].CGColor;
    self.trackLayer.borderColor = [NSColor tertiaryLabelColor].CGColor;
    self.trackLayer.borderWidth = 1.0;

    self.sliderLayer.backgroundColor = [NSColor controlColor].CGColor;

Of course, I don’t want the knob to be transparent, i. e. the track layer should not shine through. How can I work around this while preserving the dynamic tint?

Ideally, one could access the the “effective” system colors with the current tint and no transparency. But I didn’t find any API to do so.

A similar problem occurs when applying a shadow to layers that have transparent (system) colors.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.