如何在应用程序本身中包含 iOS 应用程序图标图像? [英] How do I include iOS App Icon image within the app itself?

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

问题描述

我有标准的 iOS 应用,资产中包含一个标准的应用图标.

I have standard iOS app, with a standard app icon contained in Assets.

我想在应用中显示应用图标(使用 SwiftUI).请注意,我不是在问如何设置应用程序图标或动态更改图标.我只想在应用自己的设置"视图中显示应用图标.

I'd like to display the app icon within the app (using SwiftUI). Note that I am not asking how to set the app icon, or change the icon dynamically. I just want to show the app icon within the app's own Settings view.

看起来应用程序图标资产应该与其他任何资产一样,我可以使用以下内容将其包含在内(请注意,默认图标命名中应用程序和图标之间没有空格),

It would appear the App Icon asset should just be like any other, and I could include it using the following (note there is no space between App and Icon in the default icon naming),

Image("AppIcon")

我也尝试过,

Image("icon_60pt@3x.png") // Pick out a specific icon by filename
Image("icon_60pt@3x") // Maybe it assumes it's a .png
Image("icon_60pt") // Maybe it auto picks most appropriate resolution, like UIKit

...但这些都不起作用.

...but none of these work.

如何在应用程序中包含应用程序自己的图标,而不将其复制为单独的图像集(我已经尝试过,并且确实有效.)

How do I include the apps own icon within the app, without duplicating it as a separate Image Set (which I have tried, and does work.)

谢谢.

推荐答案

以下有效如果应用图标为使用的设备正确设置(即 iPhone 的 iPhone 图标等)

The following works if app icon is correctly set for used device (ie. iPhone icons for iPhone, etc.)

注意:应用图标的大小必须完全匹配!

使用 Xcode 11.4 测试

Tested with Xcode 11.4

Image(uiImage: UIImage(named: "AppIcon") ?? UIImage())

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

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