简体   繁体   English

如何扩展不同大小的iOS应用程序图标

[英]How to scale iOS app icon for different sizes

With every change to an app icon there is the need to generate the proper icon sizes for Xcode. 随着对应用程序图标的每次更改,都需要为Xcode生成正确的图标大小。 I've always been looking for an efficient way to generate those icons. 我一直在寻找一种有效的方法来生成这些图标。

It's obvious that an automated process won't care of pixel fitting or similar details. 很明显,自动化过程不关心像素拟合或类似细节。 But a simple AppleScript should do the trick for most of us. 但对于我们大多数人来说,简单的AppleScript应该可以解决问题。

The following screen shows all those sizes needed: 以下屏幕显示了所需的所有尺寸:

在此输入图像描述

I've gathered different sources and made a simple working script for everyone to share... so here you go – just check my answer below . 我收集了不同的资料并制作了一个简单的工作脚本供大家分享......所以你去了 - 只需查看下面的答案

Here is a simple AppleScript for all of you... feel free to adapt and use it: 这是一个简单的AppleScript,适合所有人...随意适应和使用它:

on run
    set f to choose file
    processTheFiles({f})
end run

on open theFiles
    processTheFiles(theFiles)
end open

on processTheFiles(theFiles)
    tell application "Image Events" to launch
    repeat with f in theFiles
        set thisFile to f as text

        -- iPhone       
        scaleAndSave(f, thisFile, 29 * 1, "-iPhone-29")
        scaleAndSave(f, thisFile, 29 * 2, "-iPhone-29@2x")
        scaleAndSave(f, thisFile, 40 * 2, "-iPhone-40@2x")
        scaleAndSave(f, thisFile, 57 * 1, "-iPhone-57")
        scaleAndSave(f, thisFile, 57 * 2, "-iPhone-57@2x")
        scaleAndSave(f, thisFile, 60 * 2, "-iPhone-60@2x")

        -- iPad
        scaleAndSave(f, thisFile, 29 * 1, "-iPad-29")
        scaleAndSave(f, thisFile, 29 * 2, "-iPad-29@2x")
        scaleAndSave(f, thisFile, 40 * 1, "-iPad-40")
        scaleAndSave(f, thisFile, 40 * 2, "-iPad-40@2x")
        scaleAndSave(f, thisFile, 50 * 1, "-iPad-50")
        scaleAndSave(f, thisFile, 50 * 2, "-iPad-50@2x")
        scaleAndSave(f, thisFile, 72 * 1, "-iPad-72")
        scaleAndSave(f, thisFile, 72 * 2, "-iPad-72@2x")
        scaleAndSave(f, thisFile, 76 * 1, "-iPad-76")
        scaleAndSave(f, thisFile, 76 * 2, "-iPad-76@2x")

    end repeat
    tell application "Image Events" to quit
end processTheFiles

on scaleAndSave(aPath, aFile, aSize, aName)
    set savePath to text 1 thru -5 of aFile & aName & text -4 thru -1 of aFile
    tell application "Image Events"
        set a to open aPath
        scale a to size aSize
        save a in savePath
    end tell
    delay 0.2
end scaleAndSave

Here is the same as a file... just download, save, double click and run: https://dl.dropboxusercontent.com/u/170740/AppIcon.applescript 这与文件相同...只需下载,保存,双击并运行: https//dl.dropboxusercontent.com/u/170740/AppIcon.applescript

I hope, this saves you some time... 我希望,这可以节省你一些时间......

I have done a shell script that I added as a build script to one of my projects. 我已经完成了一个shell脚本,我将其作为构建脚本添加到我的一个项目中。 It generates all icons from the biggest one: 它会生成最大的图标:

# Generate all icon files from Icon_1024.png

#smaller app store icon
sips --resampleWidth 512 Icon_1024.png --out Icon_512.png

#iphone icons
sips --resampleWidth 114 Icon_1024.png --out Icon\@2x.png
sips --resampleWidth 57 Icon_1024.png --out Icon.png

#ipad icons
sips --resampleWidth 144 Icon_1024.png --out Icon-72\@2x.png
sips --resampleWidth 72 Icon_1024.png --out Icon-72.png

This will generate icons needed for ios 10 and 11: 这将生成ios 10和11所需的图标:

sips --resampleWidth 167 icon1024.png --out icon167.png
sips --resampleWidth 152 icon1024.png --out icon152.png
sips --resampleWidth 76 icon1024.png --out icon76.png
sips --resampleWidth 80 icon1024.png --out icon80.png
sips --resampleWidth 40 icon1024.png --out icon40.png
sips --resampleWidth 58 icon1024.png --out icon58.png
sips --resampleWidth 29 icon1024.png --out icon29.png
sips --resampleWidth 20 icon1024.png --out icon20.png
sips --resampleWidth 180 icon1024.png --out icon180.png
sips --resampleWidth 120 icon1024.png --out icon120.png
sips --resampleWidth 87 icon1024.png --out icon87.png
sips --resampleWidth 60 icon1024.png --out icon60.png

Just open terminal in directory with icon1024.png and paste what is above to generate all needed icons. 只需用icon1024.png在目录中打开终端并粘贴上面的内容即可生成所有需要的图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM