iOS 10.3中的备用图标 [英] Alternate Icon in iOS 10.3

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

问题描述

我有关于如何在iOS 10.3中设置备用图标的信息,在Info.plist中添加密钥。但是,我不确定每个替代品需要哪种尺寸。我现在使用资源文件夹,并且必须为聚光灯,不同的iphone和ipad尺寸等提供大约12种不同尺寸的图标。其他的规则是什么?

I have the info on how to set up alternate icons in iOS 10.3 adding the key in the Info.plist. However, what I am not sure of is which sizes are needed for each alternate. I use assets folders right now, and have to put in about 12 different sized icons for spotlight, different iphone and ipad sizes, etc. What's the rule on the alternate ones?

这不是重复的可能性。它询问你是否必须为备用图标包含每一个尺寸

This is not a duplicate of is it possible. It is asking if you have to include every single size for the alternate icons

推荐答案

因为最大的问题是如何配置图标图像源和info.plist,此处是一个示例,告诉您如何在iOS 10.3中设置备用图标,在Swift 3中实现。

Since the biggest problem is how to configure the icon image source and info.plist, here is a sample to tell you how to set alternate icons in iOS 10.3, implemented in Swift 3.



  1. 如果您的应用不支持iPad,则图标图像源可以是60pt @ 2x和60pt @ 3x(120x120 180x180),并且20pt 29pt和40pt都可以从60pt图像生成。因此,您的备用图标图片来源也应为60pt @ 2x和60pt @ 3x ,如果它是仅限iPhone的应用程序。如果你的应用程序支持iPad Pro,它应该是83.5pt。

  1. If your app doesn't support iPad, the icon image source can be 60pt@2x and 60pt@3x (120x120 180x180), and the 20pt 29pt and 40pt all can be generated from the 60pt image. So, your alternate icon image source should also be 60pt@2x and 60pt@3x, if it is a iPhone-only app. And it should be 83.5pt, if your app supports iPad Pro.

就像你在图片中看到的那样,备用图标图像应该添加将项目作为png文件(我的样本中的blackBgColor图像),但未添加到Assets.xcassets。

Like what you saw in the picture, the alternate icon image should be added to the project as a png file (the blackBgColor image in my sample), but not added to Assets.xcassets.

备用配置info.plist中的图标有点复杂,所以如果这是你第一次这样做,我建议你用plist复制我的代码。并且,注意我的替代图标的名称(blackBgColor)已经在plist中使用了TWICE ,如果您要根据我的版本更改图标的名称,请确保您更改了两个地方的名称。

The configuration for alternate icons in info.plist is kinda complicated, so if this is your first time doing this, I suggest you copy my code in plist. And, notice my alternate icon's name (blackBgColor) has beed used TWICE in plist, if you are gonna change the icon's name based on my version, make sure you changed the name in both of the two places.

<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>blackBgColor</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>blackBgColor</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
    </dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>AppIcon60x60</string>
        </array>
    </dict>
</dict>


现在,ViewController中的代码很简单。

Now, code in ViewController will be simple.

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func changeAppIcon(_ sender: Any) {

        if UIApplication.shared.supportsAlternateIcons {
            print("you can change this app's icon")
        }else {
            print("you cannot change this app's icon")
            return
        }

        if let name = UIApplication.shared.alternateIconName {
            // CHANGE TO PRIMARY ICON
            UIApplication.shared.setAlternateIconName(nil) { (err:Error?) in
                print("set icon error:\(String(describing: err))")
            }
            print("the alternate icon's name is \(name)")
        }else {
            // CHANGE TO ALTERNATE ICON
            UIApplication.shared.setAlternateIconName("blackBgColor") { (err:Error?) in
                print("set icon error:\(String(describing: err))")
            }
        }
    }

}

这篇关于iOS 10.3中的备用图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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