[英]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? 如何使用Cocoa为我的应用程序的Dock图标添加徽章? 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.) (我指的是在Mail,iChat等中显示的徽章类型,以指示未读邮件等的数量。)
Cocoa Touch does provide one such method, but I haven't been able to find any equivalent for a regular Cocoa application. Cocoa Touch确实提供了一种这样的方法,但是我无法找到常规Cocoa应用程序中的任何等效方法。
It should be noted that NSDockTile is only available on Leopard. 应该注意的是,NSDockTile仅在Leopard上可用。 If you need to target Tiger you'll need to use
-setApplicationIconImage:
on your NSApplication object and draw your badge by hand. 如果您需要定位Tiger,则需要在NSApplication对象上使用
-setApplicationIconImage:
并手动绘制徽章。
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. 另外,它不在发行说明之外的文档中,但是我可以通过将
dockTile
消息发送到NSApplication对象来获得应用程序的停靠图块。
NSDockTile *tile = [[NSApplication sharedApplication] dockTile];
[tile setBadgeLabel:@"Lots"];
Use 采用
[[[NSApplication sharedApplication] dockTile] setBadgeLabel:@"2234"];
This method, and the NSDockTile
class, has been available since Leopard. 从Leopard开始,此方法以及
NSDockTile
类已可用。
A quick google search turned up the NSDockTile class. 快速的Google搜索打开了NSDockTile类。 Seems pretty self-explanatory once you take a gander at the documentation.
一旦您对文档有所了解,似乎就很容易解释了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.