I want to put an icon in Mac OS status bar as part of my cocoa application. What I do right now is:
NSStatusBar *bar = [NSStatusBar systemStatusBar];
sbItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[sbItem retain];
[sbItem setImage:[NSImage imageNamed:@"Taski_bar_icon.png"]];
[sbItem setHighlightMode:YES];
[sbItem setAction:@selector(stopStart)];
but if I want the icon to be animated (3-4 frames), how do I do it?
You'll need to repeatedly call
-setImage:
on yourNSStatusItem
, passing in a different image each time. The easiest way to do this would be with anNSTimer
and an instance variable to store the current frame of the animation.Something like this:
I re-wrote Rob's solution so that I can reuse it:
I have number of frames 9 and all the images name has last digit as frame number so that I can reset the image each time to animate the icon.
How to use:
Conform to protocol in your StatusMenu class
Implement protocol method
Just had to do something similar recently in a simple project, so I'm posting my personal version written in Swift:
Usage: