1
votes

I am writing a custom NSMenuItem view. I would like to be able to use the system default "on state" menu item image (the image named NSImageNameMenuOnStateTemplate) within an NSImageView subview of my custom NSMenuItem view.

The checkmark image looks fine when the menu item is not selected. When selected, I need to somehow draw the image in white instead of the normal dark gray color. Otherwise, the dark gray checkmark is barely visible against the dark blue selected menu item background:

Screen shot of the dark gray checkmark against the dark blue selected menu item background

How do I draw the white checkmark image?

1

1 Answers

0
votes

I found that I can change the checkmark image color by setting the backgroundStyle of the NSImageCell associated with the NSImageView. If the menu item is selected, setting the backgroundStyle to NSBackgroundStyleDark will produce a white checkmark. If the menu item is not selected, setting the backgroundStyle to NSBackgroundStyleLight will produce the normal dark-gray checkmark:

[stateImageView.cell setBackgroundStyle:(isSelected
                                         ? NSBackgroundStyleDark
                                         : NSBackgroundStyleLight)];

If the menu item is disabled, I can produce a disabled checkmark appearance by disabling the cell:

[stateImageView.cell setEnabled:NO];