简体   繁体   English

如何获得Finder中使用的桌面图标?

[英]How do I get the desktop icon used in Finder?

In Objective-c/Cocoa, how do I get the icon that Finder uses for the desktop (it looks like the black/pink nebula desktop image with a menu bar and dock). 在Objective-c / Cocoa中,如何获取Finder用于桌面的图标(它看起来像带有菜单栏和停靠点的黑色/粉红色星云桌面图像)。

I tried this: 我尝试了这个:

NSImage *icon = [[NSWorkspace sharedWorkspace] 
                 iconForFileType: NSFileTypeForHFSTypeCode(kDesktopIcon)];

But all I get is a blue folder with a ghosted desktop-looking box on it. 但是我所得到的只是一个蓝色的文件夹,上面有一个看起来像桌面的盒子。 Is there another constant that provides this icon, or another method altogether for getting the icon? 是否有提供此图标的另一个常量,或提供该图标的另一种方法?

The icon you're looking for is located at: /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDesktopFolderIcon.icns 您要查找的图标位于:/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDesktopFolderIcon.icns

I wasn't able to find a constant for it, but you could load the image in with imageWithContentsOfFile:. 我无法为其找到常量,但是您可以使用imageWithContentsOfFile:加载图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在适用于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? 如果您必须使用文件夹的自定义图标,您如何以编程方式将文件夹图标放在Finder侧边栏上? - How do you programmatically put folder icons on the Finder sidebar, given that you have to use a custom icon for the folder? 如何在应用程序中创建Finder别名? - How do I create a Finder alias within an application? 如何获取用户Mac的图标? - How do I get the icon of the user's Mac? 如何通过 Mac App 以编程方式聚焦桌面/Finder? - How to programmatically focus Desktop/Finder via Mac App? 如何获得小箭头查找器放在别名上? - How to get the little arrow Finder puts on aliases? 如何获得Finder之类的FSCopyObjectAsync的根权限 - How to get root permissions for FSCopyObjectAsync like Finder 如何将自己的选项添加到Finder的右键菜单? - How do I add my own option to Finder's right click menu? 将项目表单NSCollectionView拖动到Finder时如何获取拖动目标网址 - How to get the drag destination url when I drag item form NSCollectionView to Finder 如何使用图标向UITextField添加填充 - How do I add padding to a UITextField with an icon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM