|Jun 9, 2012, 05:41 PM||#1|
Change image when NSMenuItem highlights?
Does anyone have any suggestions for how to set up an NSMenuItem to have two images that it alternates between based on whether it's currently highlighted or not?
The best I have so far is I change the item's image whenever the delegate receives either menuWillOpen or menuDidClose.
This has two issues, unfortunately:
1 - There's a slight, but noticeable, delay when the item is highlighted.
2 - It's possible to have a menu open but not actually highlight the item. (IE, if the item is the first one in the menu, you can move the cursor above the menu. The submenu will remain open, but the highlight will go away. Leaving me with a highlighted icon, but not a highlighted item.)
I've attempted to subclass NSMenuItem and see if various method names get called ever... (things like setHighlighted:, setIsHighlighted:, isHighlighted) but none work...
I can't believe how difficult this seems to be. Apple's own built in menus perform this. (Just click on the wi-fi menu and highlight an item. Notice that the various icons change from black to white when you highlight them.)
I've discovered a delegate method, menu:willHighlightItem:, which has proven to be very useful for properly changing an item's image right when it gets highlighted.
The delegate occasionally isn't called when it should be. (The documentation says it gets called with item being nil when all the items are being unhighlighted... but it doesn't if the cursor simply moves back to the supermenu.)
So... my code looks like this, and since the menuItems with the images that should change back and forth each have submenus, I can just look for when the menu closes.
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
Last edited by ArtOfWarfare; Jun 10, 2012 at 02:16 PM.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|iPad Mini: Apple.com Change In Image Retention||nanogirl21||iPad||1||Nov 16, 2013 05:49 AM|
|Can't change my desktop image.||fingleburt||Mac OS X 10.7 Lion||0||Jun 15, 2013 02:37 PM|
|Symbols in image file change||kcll12||Mac Basics and Help||0||May 1, 2013 07:23 PM|
|How to change image from another class||Abrexas||iPhone/iPad Programming||25||Apr 20, 2013 12:47 AM|
|How to Change Login Image?||smitka351||MacBook Pro||1||Feb 5, 2013 04:37 PM|
All times are GMT -5. The time now is 09:32 AM.