xcode 如何获取 AppIcon 的 UIImage?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22808416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get UIImage of AppIcon?
提问by samwize
I am using Assets Catalog, and adding app icon of various size to the assets is okay.
我正在使用资产目录,向资产添加各种大小的应用程序图标是可以的。
But when I tried to get the UIImage programmatically, it returned nil.
但是当我尝试以编程方式获取 UIImage 时,它返回 nil。
UIImage *appIcon = [UIImage imageNamed"AppIcon"];
The app icon is named AppIcon
(the default), and the actual files are app-icon-256.png
etc.
应用程序图标已命名AppIcon
(默认),实际文件是app-icon-256.png
等。
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
.
我还注意到,与普通图像不同,应用程序图标位于 .app 目录中的“应用程序图标”集中AppIcon.appiconset
。普通图像在目录中someimage.imageset
。
回答by rckoenes
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编译后没有放到目录中。就像以前一样,将它复制到您的应用程序包中。
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
将图标复制到应用程序包时使用的名称转换是AppIcon<size>.png
,其中大小例如40x40
或72x72
You can get your apps icons by specifying the size of the app icon you want:
您可以通过指定所需应用程序图标的大小来获取应用程序图标:
UIImage *appIcon = [UIImage imageNamed:@"AppIcon40x40"];