In Mac Catalyst, there is a default toolbar item that shows a color panel.
https://developer.apple.com/documentation/appkit/nstoolbaritem/identifier/1531463-showcolors
It shows up just fine, but I can't find a way to detect a color change from this color panel. Does anyone know how to do this?
When the toolbar item is clicked, an instance of
NSColorPanel
is shown. The selected color can be accessed fromNSColorPanel.color
, but we don't have a reference to the shown panel. Even the classNSColorPanel
isn't visible to Mac Catalyst apps.Fortunately, there is a notification that is posted when a color is selected in a color panel. So, all we need is to observe that notification to get a reference to the
NSColorPanel
instance, and then access itscolor
property: