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

本小妞迷上赌 提交于 2019-11-28 17:53:46

Use

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

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

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"];

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!