如何获得AppIcon的UIImage? [英] How to get UIImage of AppIcon?

查看:641
本文介绍了如何获得AppIcon的UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用资产目录,并且可以向资产添加各种大小的应用程序图标。

I am using Assets Catalog, and adding app icon of various size to the assets is okay.

但是当我尝试以编程方式获取UIImage时,它返回了nil 。

But when I tried to get the UIImage programmatically, it returned nil.

UIImage *appIcon = [UIImage imageNamed"AppIcon"];

应用程序图标名为 AppIcon (默认),实际文件是 app-icon-256.png 等。

The app icon is named AppIcon (the default), and the actual files are app-icon-256.png etc.

我也注意到了普通图像,应用程序图标位于应用程序图标集中,位于目录 AppIcon.appiconset 中。普通图像位于目录 someimage.imageset

I also noticed that unlike normal images, app icons are in an "App Icon" set, in the directory AppIcon.appiconset. Normal images are in the directory someimage.imageset.

推荐答案

问题是编译后资产目录中的AppIcon没有放在目录中。将其复制到您的应用包中,就像之前一样。

The problem is that the AppIcon from the asset catalog is not placed in the the catalog after compiling. Instated it it copied into your apps bundle, just like before.

将图标复制到应用包时使用的名称转换为 AppIcon< size> ; .png ,其中大小为 40x40 72x72

The name conversion used when copying the icon to the app bundle is AppIcon<size>.png, where the size is for example 40x40 or 72x72

您可以通过指定所需应用程序图标的大小来获取应用程序图标:

You can get your apps icons by specifying the size of the app icon you want:

UIImage *appIcon = [UIImage imageNamed:@"AppIcon40x40"];

这篇关于如何获得AppIcon的UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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