OGeek|极客世界-中国程序员成长平台

标题: ios - 这是否可以将替代图标应用于 iOS 应用程序? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:21
标题: ios - 这是否可以将替代图标应用于 iOS 应用程序?

我需要根据地区更改应用图标,可以吗?



Best Answer-推荐答案


是的,从 iOS 10.3 开始可以做到这一点。

首先,您需要在 Info.plist 文件中定义所有替代图标,您无法动态获取它们。

在下面的示例中,我们定义了 2 个替代图标:“de”和“fr”:

<key>CFBundleIcons</key>
 <dict>
  <key>CFBundleAlternateIcons</key>
  <dict>
   <key>de</key>
   <dict>
    <key>CFBundleIconFiles</key>
    <array>
     <string>ic_de</string>
    </array>
    <key>UIPrerenderedIcon</key>
    <false/>
   </dict>
   <key>fr</key>
   <dict>
    <key>CFBundleIconFiles</key>
    <array>
     <string>ic_fr</string>
    </array>
    <key>UIPrerenderedIcon</key>
    <false/>
   </dict>
  </dict>
  <key>CFBundlePrimaryIcon</key>
  <dict>
   <key>CFBundleIconFiles</key>
   <array>
    <string>ic_none</string>
   </array>
  </dict>
 </dict>

然后您可以根据您喜欢的任何内容(游戏进度、天气状况、高级用户等)设置图标名称。要更改图标使用:

UIApplication.shared.setAlternateIconName("de") { (error) in
    if let error = error {
        print("err: \(error)")
        // icon probably wasn't defined in plist file, handle the error
    }
}

结果:

Gif showing the icon changing in response to a segmented control

gif 来自 a Medium article by Julien Quéré .

关于ios - 这是否可以将替代图标应用于 iOS 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43083272/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4