如何获取用户 Mac 的图标?
使用 Objective-C 和 Cocoa,有谁知道如何获取用户计算机的图标(显示在 Finder 中“设备”和“网络”下的图标)?不是硬盘图标,而是用户设备的实际图标。它的范围从 MacBook 图标到 Mac Pro 图标再到 Windows 蓝屏死机监视器图标。
我已经尝试过以下方法:
NSImage *icon = [[NSWorkspace sharedWorkspace]
iconForFileType: NSFileTypeForHFSTypeCode(kComputerIcon)];
但显然,它总是返回相同的图标。我还尝试了 iconForFile:
方法,但我不知道用作参数的文件路径。有人能指出我正确的方向吗?
Using Objective-C and Cocoa, does anyone know how to get the icon for a user's computer (the one that shows under "Devices" and "Network" in Finder)? Not the harddisk icon, the actual one for a user's device. It ranges from a MacBook icon to the Mac Pro icon to a Windows blue screen of death monitor icon.
I've tried stuff along the following lines:
NSImage *icon = [[NSWorkspace sharedWorkspace]
iconForFileType: NSFileTypeForHFSTypeCode(kComputerIcon)];
But that just returns the same icon all the time, obviously. I've also tried the iconForFile:
method but I don't know of a file path to use as the parameter. Can anybody point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将返回当前计算机的图标
This will return the icon of the current computer
另一个查找图标的地方:
您可以使用其中的文件创建 NSImage 对象,如下所示:
但是,可能不建议像这样对值进行硬编码,因为 Apple 可能会更改图标的位置。有一个名为 IconsCore.h 的文件,其中包含许多其他常量值,例如“kToolbarDesktopFolderIcon”,可以按如下方式使用:
不过,我相信这些常量仅在 Snow Leopard 中有效。
Another place to look for icons:
You can create NSImage objects with the files in there like this:
It's probably not recommended to hard-code the value like that, however, since Apple may change the icons' locations. There is a file called IconsCore.h that contains many other constant values such as 'kToolbarDesktopFolderIcon' which can be used as follows:
I believe these constants only work in Snow Leopard, though.
如果您正在寻找任何其他系统图标,请查看 Apple 名为“IconCollection”的示例项目。 http://developer.apple.com/mac/library/samplecode/IconCollection /listing5.html
该示例附带了一个 plist 文件,其中包含相当多的系统图标的名称和代码,可以使用以下命令进行访问:
其中codeStr是icons.plist中提供的图标的字符串代码
If you are looking for any other system icons check out Apple's sample project called "IconCollection". http://developer.apple.com/mac/library/samplecode/IconCollection/listing5.html
The sample comes with a plist file that has the names and codes for quite a few system icons that can be accessed using;
where codeStr is the string code for the icon provided in icons.plist