Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a badge on my Dock icon using Cocoa?

How do I add a badge to the Dock icon for my app using Cocoa? Is there any roughly "standardized" way to do this?

(I'm referring to the kind of badges that show up in Mail, iChat etc. to indicate the number of unread messages and the like.)

Cocoa Touch does provide one such method, but I haven't been able to find any equivalent for a regular Cocoa application.

like image 914
Debajit Avatar asked Dec 25 '08 13:12

Debajit


3 Answers

Use

 [[[NSApplication sharedApplication] dockTile] setBadgeLabel:@"2234"];

This method, and the NSDockTile class, has been available since Leopard.

like image 72
Tristan Avatar answered Nov 07 '22 06:11

Tristan


It should be noted that NSDockTile is only available on Leopard. If you need to target Tiger you'll need to use -setApplicationIconImage: on your NSApplication object and draw your badge by hand.

Also, it's not in the documentation outside of the release notes that I could find but you get your application's dock tile by sending the dockTile message to your NSApplication object.

NSDockTile *tile = [[NSApplication sharedApplication] dockTile];
[tile setBadgeLabel:@"Lots"];
like image 25
Ashley Clark Avatar answered Nov 07 '22 07:11

Ashley Clark


A quick google search turned up the NSDockTile class. Seems pretty self-explanatory once you take a gander at the documentation.

like image 17
wfarr Avatar answered Nov 07 '22 05:11

wfarr