如何在 Xcode 中为 Mac 应用程序设置图标? [英] How can I set the icon for a Mac Application in Xcode?

查看:81
本文介绍了如何在 Xcode 中为 Mac 应用程序设置图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学到了很多关于在 Interface Builder 中编写 Objective-C 代码和设计的知识,我想为我的简单程序设置图标.

I have been learning a lot about writing Objective-C code and designing in Interface Builder and I wanted to set icons for my simple programs.

我在 Icon Composer 的所有大小字段中添加了相同的 JPG 并获得了一个 ICNS,但我不知道如何将其添加到项目中.

I added the same JPG to all the size fields in Icon Composer and got an ICNS, but I couldn't figure out how to add it to the project.

提前致谢.

推荐答案

由于 Xcode 4.4 Icon Composer 不再是创建图标的推荐方式,并且不再包含在 Xcode 的标准安装中.由于 Mac 推出了 Retina 显示屏,现在建议提供包括应用图标在内的所有图形的高分辨率版本.

Since Xcode 4.4 Icon Composer is no longer the recommended way to create icons and is no longer included in the standard install of Xcode. Due to the introduction of Macs with retina display, it is now recommended to provide high resolution versions of all graphics including app icons.

要在 Xcode > 4.4 下为您的应用提供一个图标,请执行以下操作:

To give your app an icon under Xcode > 4.4 do the following:

  1. 在 Finder 中创建文件夹 [IconName].iconset

  1. Create a folder [IconName].iconset in Finder

在此文件夹中,将您的图标放置为 png 文件.你需要图标尺寸为 16px、32px、64px(仅限视网膜)、128px、256px、512px 和1024 像素(仅限视网膜)

In this folder place your icon as png files. You'll need the icon in sizes of 16px, 32px, 64px (retina only), 128px, 256px, 512px and 1024px (retina only)

这些图标必须以 icon_16x16.png 模式命名,icon_32x32.png、icon_128x128.png等

These icons must be named with the pattern icon_16x16.png, icon_32x32.png, icon_128x128.png and so on

要支持 Retina 显示,您还必须添加带有双字符的图标文件分辨率,命名为 icon_16x16@2x.png(大小为 32x32),icon_32x32@2x.png(大小为 64x64)等等直到 icon_512x512@2x.png(大小为 1024x1024).

To support retina displays you must also add icon files with double resolution, named icon_16x16@2x.png (with size 32x32), icon_32x32@2x.png (size 64x64) and so on up to icon_512x512@2x.png (size 1024x1024).

将此 [IconName].iconset 文件夹拖到 Xcode(如有必要,请复制)

drag this [IconName].iconset folder to Xcode (copy if necessary)

在 info.plist 文件中将CFBundleIconFile"(图标文件作为键)值设置为[IconName] 但没有 .iconset 扩展名

in the info.plist file set the "CFBundleIconFile" (Icon File as Key) value to [IconName] but without the .iconset extension

注释:

  • (目前)不需要提供@2x 图标
  • 如果您不提供每个图标文件,它(通常)也会起作用
  • iconset 文件夹不应包含 icon_64x64.png 文件.64px 图标仅适用于 icon_32x32 的视网膜版本

更新:最后你的 .iconset 文件夹有以下 10 个项目:

Update: In the end your .iconset folder has the following 10 items:

icon_16x16.png
icon_16x16@2x.png
icon_32x32.png
icon_32x32@2x.png
icon_128x128.png
icon_128x128@2x.png
icon_256x256.png
icon_256x256@2x.png
icon_512x512.png
icon_512x512@2x.png

官方指南:

https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html

要将 iconset 文件夹转换为 icns 文件,请在终端上运行以下命令:

iconutil -c icns [IconName].iconset

其中 [IconName] 应替换为图标集文件夹的前缀.您现在有一个名为 [IconName].icns 的文件.在 Xcode 4.4 中,在 Target Summary 中,右键单击图标的问号,然后选择 icns 文件.然后,您应该会看到问号被替换为图标.

where [IconName] should be replaced with the prefix of the iconset folder. You now have a file called [IconName].icns. In Xcode 4.4, in the Target Summary, right click the question mark for the icon, then select the icns file. You should then see the question mark get replaced with the icon.

这篇关于如何在 Xcode 中为 Mac 应用程序设置图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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