Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

ios - How to get UIImage of AppIcon?

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 *appIcon = [UIImage imageNamed"AppIcon"];

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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"];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...