Monday, April 30, 2018

NSColor, CGColor, and Layers

Jeff Nadeau (tweet):

NSColor is dynamic, so its exact color value depends on the view’s context. CGColor isn’t dynamic, so resolving a CGColor produces a snapshot from the current context at the moment you ask for it. As your view’s context changes, you’ll be left with a stale value that might look very wrong compared to the surrounding UI.

[…]

Besides the obvious NSAppearance changes which can occur (vibrancy, Increased Contrast mode, etc.), there are more subtle ones. For example, in the Touch Bar there are specific elements of the UI that get white balanced automagically as ambient light readings change. […] The amount of context-sensitivity is only going to increase over time.

[…]

The layer tree is a side effect of the view hierarchy, not its model. This probably annoys UIKit people a lot, but this approach is extremely intentional.

Comments RSS · Twitter

Leave a Comment