简体   繁体   English

如何使用可可粉在我的Dock图标上绘制徽章?

[英]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.

相关问题 如何在可可粉中绘制正方形网格? - How do I draw a grid of squares in Cocoa? 如何从坞站中删除图标但保留在cmd-tab(可可)中 - How to remove Icon from dock but keep in cmd-Tab (Cocoa) 如何使用Cocoa标记文件和文件夹 - How to badge file and folder using Cocoa 使用菜单栏的Cocoa应用程序,但没有Dock图标/开关菜单 - Cocoa Application with Menubar but no Dock Icon / switch menu 可可:在运行时添加另一个停靠图标 - Cocoa: add another dock icon at runtime 如何在Cocoa中绘制图像网格并将其导出为PDF? - How do I draw a grid of images in Cocoa and export it to a PDF? 当文件,图片等放在其停靠栏图标上时,如何让OS X应用程序做出反应? - How do I make an OS X application react when a file, picture, etc is dropped on its dock icon? 如何在用户右键单击Mac上cocoa app的dock-icon时创建菜单? - How to create a menu when a user right-clicks on the dock-icon of cocoa app on Mac? 在适用于macOS的Cocoa应用程序中,我使用NSFileWrapper将捆绑包保存到磁盘。 如何使取景器为我的捆绑包显示正确的图标? - In a Cocoa Application for macOS, I save a bundle to disk using NSFileWrapper. How can I get the finder show the correct icon for my bundle? 如何使用UIBezierPath在可可触摸中绘制多边形 - How to draw polygons in cocoa touch using UIBezierPath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM