Xcode 5 & Asset Catalog: How to reference the LaunchImage?
This is the (almost) complete list of the LaunchImage (excluding the iPad images with no status bar):
- LaunchImage-568h@2x.png
- LaunchImage-700-568h@2x.png
- LaunchImage-700-Landscape@2x~ipad.png
- LaunchImage-700-Landscape~ipad.png
- LaunchImage-700-Portrait@2x~ipad.png
- LaunchImage-700-Portrait~ipad.png
- LaunchImage-700@2x.png
- LaunchImage-Landscape@2x~ipad.png
- LaunchImage-Landscape~ipad.png
- LaunchImage-Portrait@2x~ipad.png
- LaunchImage-Portrait~ipad.png
- LaunchImage.png
- LaunchImage@2x.png
- LaunchImage-800-667h@2x.png (iPhone 6)
- LaunchImage-800-Portrait-736h@3x.png (iPhone 6 Plus Portrait)
- LaunchImage-800-Landscape-736h@3x.png (iPhone 6 Plus Landscape)
- LaunchImage-1100-Portrait-2436h@3x.png (iPhone X Portrait)
- LaunchImage-1100-Landscape-2436h@3x.png (iPhone X Landscape)
- (NSString *)splashImageNameForOrientation:(UIInterfaceOrientation)orientation { CGSize viewSize = self.view.bounds.size; NSString* viewOrientation = @"Portrait"; if (UIDeviceOrientationIsLandscape(orientation)) { viewSize = CGSizeMake(viewSize.height, viewSize.width); viewOrientation = @"Landscape"; } NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"]; for (NSDictionary* dict in imagesDict) { CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]); if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) return dict[@"UILaunchImageName"]; } return nil;}
The LaunchImages are special, and aren't actually an asset catalog on the device. If you look using iFunBox/iExplorer/etc (or on the simulator, or in the build directory) you can see the final names, and then write code to use them - eg. for an iOS7-only iPhone-only project, this will set the right launch image:
NSString *launchImage;if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && ([UIScreen mainScreen].bounds.size.height > 480.0f)) { launchImage = @"LaunchImage-700-568h";} else { launchImage = @"LaunchImage-700";}[self.launchImageView setImage:[UIImage imageNamed:launchImage]];
I put this into viewDidLoad.
This isn't really ideal, it would be great if Apple would give us a nice API to do this.