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.
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.
- Form Data Request using NSURLConnection in iOS
- Since Xcode 8 and iOS10, views are not sized properly on viewDidLayoutSubviews
- App not sized properly iOS 8 iPhone simulator
- How to prevent load of meteor.local (when building ios app with phonegap)
- With UIPanGestureRecognizer, is there a way to only act so often, like after x many pixels were panned?
- Inconsistent Today Widget behavior breaks subview's height constraints
- How to use addSkipBackupAttributeToItemAtURL API?
- Facebook iOS 3.1 sdk login with publish permission callbacks
- UIAlertController custom font, size, color
- Does calling a method inside a block that calls another method referring to self cause a retain cycle?
- Send Image as a binary file to the server
- How to set a max limit for an IBInspectable Int
- Animate popoverContentsize when pushing navigation view controller in popover on iPad
- Sprite kit side scrolling
- Convert between Decimal, Binary and Hexadecimal in Swift