Load app icon from xcassets
I’d like to display the app icon inside my app. The icon is in the default assets catalog (
How do you load it? I tried the following and they all return
image = [UIImage imageNamed:@"AppIcon"]; image = [UIImage imageNamed:@"icon"]; image = [UIImage imageNamed:@"icon-76"]; image = [UIImage imageNamed:@"icon-60"];
Other images in the assets catalog work as expected.
- Trim UIImage border
- IPA created via Xcode bot fails to run for APNS but runs if built manually via Xcode itself or built as an archive by Xcode
- iOS Swift: saving an array of custom classes
- Gradient along MKPolyLineView ( MKPolylineRenderer )
- ShareKit - posting linked image to facebook wall
- How to use custom UINavigationBar
2 Solutions Collect From Internet About “Load app icon from xcassets”
By inspecting the bundle I found that the icon images were renamed as:
AppIcon76x76~ipad.png AppIcon76x76@2x~ipad.png AppIcon60x60@2x.png
And so on.
[UIImage imageNamed:@"AppIcon76x76"] or similar works.
Is this documented somewhere?
I recommend retrieving the icon URL by inspecting the
Info.plist since there’s no guarantee how the Icon files are named:
NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary]; NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject]; imageView.image = [UIImage imageNamed:icon];
In this case we’re fetching the last image URL of the CFBundleIconFiles array. It has the largest resolution. Change this if you need a smaller resolution.
- Instance member cannot be used on type of custom class
- RestKit: How to handle empty response.body?
- Facebook iOS SDK 3.2.1 – : unrecognized selector sent to instance
- How to update our static library architecture for suporting arm64 Build?
- Unarchived Node doesn't appear when added to parent in SpriteKit
- Where to update Autolayout constraints when size changes?
- iPhone/iOS: Will there be called any method if a UIView is added as a subview
- How to send mail from iphone app without showing MFMailComposeViewController?
- How can I debug in a framework in Xcode?
- Fire a segue conditionally to multiple View Controllers
- iOS Facebook SDK Error Domain com.facebook.sdk Code 2 and Code 7
- numberOfRowsInSection is called before Alamofire connection
- Format currency with UITextField
- Make app appear as iOS 8 Suggested App at lockscreen
- MKMapView show incorrectly saved region