如何为应用程序的Mac OS X应用程序包设置图标?

时间:2009-03-14 20:30:16

标签: macos

我有一个应用程序,我已捆绑到Mac OS X应用程序包中。一切都运行正常,但我想从默认值更改其图标。如何设置其图标?感谢。

3 个答案:

答案 0 :(得分:27)

info.plist添加

<key>CFBundleIconFile</key>
<string>iconfile</string>

在资源目录中使用图标文件iconfile.icns

答案 1 :(得分:4)

如果您来到这里是因为您只有一个应用程序并且只想更改计算机上的图像(不确定它如何用于共享),则有更简单的方法。特别是,我使用了两个选项:

  1. 如果要复制现有图标:

    • 选择源项目,然后按Cmd-I(Apple-I)
    • 选择要更改的项目,然后按Cmd-I(Apple-I)
    • 将图标从源图标拖动到要更改的图标的左上角图标(示例图像显示目标图标:它是单词“bird_id 2”左侧的'文件夹'图标): enter image description here
  2. 从任何图片创建.icns文件。如果您使用MacPorts,我建议使用端口makeicns - 有关详细信息,请参阅下文。您也可以使用http://www.img2icnsapp.com/建议的https://discussions.apple.com/thread/2773825等应用来执行此操作。

  3. makeicns v1.4.10 (284bd686824f)
    
    Usage: makeicns [k1=v1] [k2=v2] ...
    
    Keys and values include:
        512: Name of input image for 512x512 variant of icon
        256: Name of input image for 256x256 variant of icon
        128: Name of input image for 128x128 variant of icon
         32: Name of input image for 32x32 variant of icon
         16: Name of input image for 16x16 variant of icon
         in: Name of input image for all variants not having an explicit name
        out: Name of output file, defaults to first nonempty input name,
             but with icns extension
    
      align: [center, left, right, top, bottom] {First letter suffices!}
    
    Examples:
    
      makeicns -512 image.png -32 image.png
          Creates image.icns with only a 512x512 and a 32x32 variant.
    
      makeicns -in myfile.jpg -32 otherfile.png -out outfile.icns
          Creates outfile.icns with sizes 512, 256, 128, and 16 containing data
          from myfile.jpg and with size 32 containing data from otherfile.png.
    

答案 2 :(得分:3)

我制作了一个小脚本,拍摄了一张大图像并将其调整为适用于Mac OS的所有预期图标大小,包括用于视网膜显示的双重图像。它需要原始的png文件,我希望它与最大尺寸一样大,如果不是更大的话,以确保它们以最高质量渲染。

它调整大小并将它们复制到图标集,然后使用Mac OS的“iconutil&#39;将它们连接到.icns文件的工具。

要运行此脚本,您需要将原始图标文件设为png,并且您的捆绑包的工作顺序或多或少。你只需要触摸前三行。

export PROJECT=Myproject
export ICONDIR=$PROJECT.app/Contents/Resources/$PROJECT.iconset
export ORIGICON=Mybigfile.png

mkdir $ICONDIR

# Normal screen icons
for SIZE in 16 32 64 128 256 512; do
sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_${SIZE}x${SIZE}.png ;
done

# Retina display icons
for SIZE in 32 64 256 512; do
sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_$(expr $SIZE / 2)x$(expr $SIZE / 2)x2.png ;
done

# Make a multi-resolution Icon
iconutil -c icns -o $PROJECT.app/Contents/Resources/$PROJECT.icns $ICONDIR
rm -rf $ICONDIR #it is useless now
相关问题