Mac OSX捆绑包的图标 [英] Icon for Mac OSX bundle

查看:211
本文介绍了Mac OSX捆绑包的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译了一个名为MyBundle.bundle的Mac OSX软件包,它用作另一个应用程序的插件。我希望捆绑包有一个独特的图标,因此我将Info.plist文件设置为:

I compile a Mac OSX bundle, called MyBundle.bundle, which is used as a plugin for another application. I want the bundle have a unique icon and so I set the Info.plist file to say:

<key>CFBundleIconFile</key>
<string>MyIcon.icns</string>

并将文件MyIcon.icns放在捆绑包的MyBundle.bundle / Contents / Resources文件夹中。

and place the file MyIcon.icns in the bundle's MyBundle.bundle/Contents/Resources folder.

这不起作用,查找程序显示该包的通用图标并忽略指定的MyIcon.icns文件。如果我将软件包的扩展名从.bundle更改为.app,则图标会立即显示 - 所以我知道Info.plist是正确的。

This does not work, the finder show a generic icon for the bundle and ignores the specified MyIcon.icns file. If I change the bundle's extension from .bundle to .app the icon immediately shows - so I know the Info.plist is correct.

我找到了一个解决方法模拟了用户在捆绑包上复制和粘贴图标:

I found a work around that simulates a user doing copy and paste of an icon on the bundle:

我将图标作为icns类型的资源和id -16455添加到捆绑包的.rsrc文件中。

I add the icon as a resource of type "icns" and id -16455 to the bundle's .rsrc file.

我致电

/Developer/Tools/SetFile -a BC MyBundle.bundle

这有效,但真的很蹩脚。从Mac OS 10.8开始,SetFile需要永远执行。

This works, but is really lame. Starting in Mac OS 10.8 SetFile takes forever to execute.

我的问题:是否有强迫Finder显示捆绑包的图标而没有这样的黑客攻击?

My question: Is there away to force the Finder to show the bundle's icon without such hacks?

BTW:关于同一主题有一个问题:设置非app mac os x bundle的图标;但唯一的答案是指示如何创建一个图标,并没有帮助解决问题。

BTW: There is a question on same subject: Set icon of non app mac os x bundle; but the only answer there instructs on how to create an icon, and does not help with the problem.

推荐答案

您可以使用NSWorkspace

You can use NSWorkspace

[[NSWorkspace sharedWorkspace] setIcon:(NSImage *)image forFile:(NSString *)fullPath options:(NSWorkspaceIconCreationOptions)options]

https://developer.apple。 com / library / mac / #documentation / Cocoa / Reference / ApplicationKit / Classes / NSWorkspace_Class / Reference / Reference.html

这篇关于Mac OSX捆绑包的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆