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.
- Xcode 5 crash when Open storyboard made from Xcode 4.6
- Can Xcode 6 and Xcode 5 coexist on the same computer?
- what is the best method to rename project name in every where from Xcode 5?
- Developing universal in Xcode 6
- Converting Country codes to country names on Device with non-english language
- Can you install the Xcode 5 Developer Preview in parallel with Xcode 4.6.2?
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.
- Change position of UIBarButtonItem in UINavigationBar
- Objective-C dynamic properties at runtime?
- MFMailComposeViewController : how do I embed a clickable URL link into the email message body
- UIWebView + Sharepoint + NTLM Auth – I get Stream is sending an event before being opened
- The concept of file's owner,first responder, and application delegate in iPhone
- After retrieving data from Firebase, how to send retrieved data from one view controller to another view controller?
- NSString sizeWithAttributes: content rect
- UIStatusBarStyle not working in Swift
- Programatically Hiding Status Bar When Adding New UIWindow?
- How to animate UITableViewCell height using auto-layout?
- How to check if an object has a stored property?
- With Auto Layout, how do I make a UIImageView's size dynamic depending on the image?
- iOS 5: Data encryption AES-256 EncryptWithKey: not found
- Swift – create custom class of type `Array`
- Is it possible to animate UIEdgeInsets?