I have a NSStatusItem, and I use an attributed string for it, setting is as such:
[statusItem setAttributedTitle:as];
where as is my attributed string. I use it to highlight certain parts of the item when certain conditions are met by coloring them differently. So my status item can have some red text and some black text, for example.
Now the problem is, when I use setAttributedTitle and then click on the status item, the colors don’t get inverted as I want them to. For instance, when I used just setTitle, the text is black when not selected and changes to white when selected. Now it just keeps the color I set it to.
Is there a way to tell it to invert colors when it’s selected? If not, how can I achieve this? Sorry, I’m a beginner in Objective-C.
Looks like the only way to do this is:
do not set a menu for the
statusItemusingsetMenu:instead, use
setAction:, change the color of the string, show the menu, and then change the color backFor instance, use something like:
And implement the
statusItemClickedmethod like this: