如何将应用程序图标包含到我的 Xcode 项目中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41537644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:42:54  来源:igfitidea点击:

How to include app icons into my Xcode project

iosxcodeiconsscreen-readers

提问by altralaser

I've a problem to include new app icons. What I've already done is the following:

我在包含新的应用程序图标时遇到了问题。我已经做的是以下内容:

I archived and validated my app and got the information that icons with the resolutions 120x120 px, 152x152 px and 167x167 px are missing. So I created that PNG files and stored it in a folder in Finder.
Then I selected the root node in the project navigator (Xcode 8.2), went to the "General" tab and opened the "App Icons and Launch Images" disclosure. There I clicked the arrow icon. The asset manager is displayed with the entry "AppIcon" selected. So far so well.
Now the documentation says that I have to drag and drop my PNG files from the Finder to that asset table.

我存档并验证了我的应用程序,并得到了分辨率为 120x120 px、152x152 px 和 167x167 px 的图标丢失的信息。所以我创建了那个 PNG 文件并将它存储在 Finder 的一个文件夹中。
然后我在项目导航器(Xcode 8.2)中选择根节点,转到“常规”选项卡并打开“应用程序图标和启动图像”披露。在那里我点击了箭头图标。资产管理器显示为选中条目“AppIcon”。到目前为止一切顺利。
现在文档说我必须将我的 PNG 文件从 Finder 拖放到该资产表中。

But my problem is that I'm a screenreader user so I can't use the mouse to handle such actions. That's why I want to ask whether there is an alternative way with a keyboard shortcut or over an import menu or maybe I can include the PNG files manually f.e. by editing the Xcode project file with a text editor? Thanks a lot for any help!

但我的问题是我是屏幕阅读器用户,所以我无法使用鼠标来处理此类操作。这就是为什么我想问是否有使用键盘快捷键或导入菜单的替代方法,或者我是否可以通过使用文本编辑器编辑 Xcode 项目文件来手动包含 PNG 文件?非常感谢您的帮助!

回答by shallowThought

The Assets.xcassetsis simply a directory whithin your projects directory. You can modify the default app icon set by placing the .png files in:

Assets.xcassets只是您的项目目录中的一个目录。您可以通过将 .png 文件放置在以下位置来修改默认应用程序图标集:

Assets.xcassets/AppIcon.appiconset

and modifying the contained Assets.xcassets/AppIcon.appiconset/Contents.jsonfile like this:

Assets.xcassets/AppIcon.appiconset/Contents.json像这样修改包含的文件:

{
    "images" : [
{
  "size" : "20x20",
  "idiom" : "iphone",
  "filename" : "yourFileName.png",
  "scale" : "2x"
},
{
  "size" : "20x20",
  "idiom" : "iphone",
  "filename" : "yourFileName.png",
  "scale" : "3x"
},
{
  "size" : "29x29",
  "idiom" : "iphone",
  "filename" : "yourFileName.png",
  "scale" : "2x"
},
{
  "size" : "29x29",
  "idiom" : "iphone",
  "filename" : "yourFileName.png",
  "scale" : "3x"
},
{
  "size" : "40x40",
  "idiom" : "iphone",
  "filename" : "yourFileName.png",
  "scale" : "2x"
},
{
  "size" : "40x40",
  "idiom" : "iphone",
  "filename" : "yourFileName.png",
  "scale" : "3x"
},
{
  "idiom" : "iphone",
  "size" : "60x60",
  "scale" : "2x"
},
{
  "idiom" : "iphone",
  "size" : "60x60",
  "scale" : "3x"
},
{
  "idiom" : "ipad",
  "size" : "20x20",
  "scale" : "1x"
},
{
  "idiom" : "ipad",
  "size" : "20x20",
  "scale" : "2x"
},
{
  "idiom" : "ipad",
  "size" : "29x29",
  "scale" : "1x"
},
{
  "idiom" : "ipad",
  "size" : "29x29",
  "scale" : "2x"
},
{
  "idiom" : "ipad",
  "size" : "40x40",
  "scale" : "1x"
},
{
  "idiom" : "ipad",
  "size" : "40x40",
  "scale" : "2x"
},
{
  "idiom" : "ipad",
  "size" : "76x76",
  "scale" : "1x"
},
{
  "idiom" : "ipad",
  "size" : "76x76",
  "scale" : "2x"
},
{
  "idiom" : "ipad",
  "size" : "83.5x83.5",
  "scale" : "2x"
}
],
"info" : {
    "version" : 1,
    "author" : "xcode"
}
}

Maybe you have to create the JSON file.

也许您必须创建 JSON 文件。

回答by Pierce

Yes there is an alternate method to drag-and-drop:

是的,有另一种拖放方法:

1) Click on the assets.xcassets

1)点击assets.xcassets

2) Right click (or control-click) "AppIcon"

2) 右键单击​​(或按住 Control 单击)“AppIcon”

3) Click "Show In Finder"

3)点击“在Finder中显示”

4) That should take you to the actual folder where the icon set gets stored. You can copy all the individual image files (make sure they are named properly for XCode to differentiate between sizes) from wherever you have them stored, and then just paste them in here via Finder.

4) 这应该会将您带到存储图标集的实际文件夹。您可以从存储它们的任何位置复制所有单个图像文件(确保它们为 XCode 正确命名以区分大小),然后通过 Finder 将它们粘贴到此处。

5) After you paste the image files in the folder, make sure they actually get pasted INSIDE the AppIcon.appiconset folder ~ they should be accessible through XCode.

5) 将图像文件粘贴到文件夹中后,确保它们确实粘贴到 AppIcon.appiconset 文件夹中~它们应该可以通过 XCode 访问。

Hope this helps

希望这可以帮助