Xcode 5 & Asset Catalog: How to reference the LaunchImage?
I am using Xcode 5's Asset Catalog, and I would like to use my LaunchImage
as the background image of my home view (a pretty common practice to make the transition from 'loading' to 'loaded' look smooth).
I would like to use the same entry in the Asset Catalog to save space and not have to replicate the image in two different Image Sets.
However, calling:
UIImage *image = [UIImage imageNamed:@"LaunchImage"]; //returns nil
This is the (almost) complete list of the LaunchImage (excluding the iPad images with no status bar):
- [email protected]
- [email protected]
- LaunchImage-700-Landscape@2x~ipad.png
- LaunchImage-700-Landscape~ipad.png
- LaunchImage-700-Portrait@2x~ipad.png
- LaunchImage-700-Portrait~ipad.png
- [email protected]
- LaunchImage-Landscape@2x~ipad.png
- LaunchImage-Landscape~ipad.png
- LaunchImage-Portrait@2x~ipad.png
- LaunchImage-Portrait~ipad.png
- LaunchImage.png
- [email protected]
- [email protected] (iPhone 6)
- [email protected] (iPhone 6 Plus Portrait)
- [email protected] (iPhone 6 Plus Landscape)
- [email protected] (iPhone X Portrait)
- [email protected] (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;
}