Re: Rendering control images in Dark Mode


Jon Gotow
 

[NSImage drawInRect:...] won't do it. NSImageView will render template images correctly, if you can somehow add one to your control, or you can use one of the methods discussed here:

https://stackoverflow.com/questions/7137705/how-to-draw-a-nsimage-like-images-in-nsbuttons-with-a-deepness/7138497#7138497

- Jon

On Oct 18, 2018, at 5:10 PM, Graham Cox <graham@mapdiva.com> wrote:

Hi all,

I have some custom controls (views) that I’m updating to be Dark Mode aware.

The view’s background is filled using the relevant semantic colour (controlBackgroundColor), and the icon is rendered using NSImage -drawInRect:… method using NSCompositngOperationSourceOver. The image has isTemplate set to YES, but the image is rendering as black rather than white (or light, anyway).

What magic do I have to do to get the template image to render appropriately in both Dark and Light mode? The documentation (and release notes) don’t seem to explain this.

—Graham

Join cocoa@apple-dev.groups.io to automatically receive all group messages.