How to make CALayer adapt to the application appearance using drawlayer:inContext:?

28 views Asked by At

I have a layer-hosting NSView subclass that draws itself using a CALayer object set as its layer. Since it's not a layer-backed view, it doesn't redraw during drawRect: nor during updateLayer, but during drawLayer:inContext: after I call setNeedsDisplay on its layer.

The problem is that the layer must adapt to the application appearance (it uses system NSColor objects), and appkit doesn't seem to manage this situation. Apple says that one needs to set the layer's content during drawRect: or updateLayer, otherwise the colors don't adapt to the appearance. Indeed, they don't update in drawLayer:inContext:

The current (ugly) solution I use is to call -display directly on the layer (which Apple says I should not do) within the updateLayer method (of another view since the view hosting the layer isn't send updateLayer, given that it's not a layer-backed view).

Calling setNeedsDisplay on the layer rather than display does not work, as the layer would not redraw its content within the updateLayer call, but after.

Is there another solution?

0

There are 0 answers