Xcode 5 & Asset Catalog: How to Reference the Launchimage

Xcode 5 Asset Catalog: How to automatically pick LaunchImage at correct size

For now, the only method i've found is to handle manually in code the LaunchImage.png:

self.splashImage.contentMode = UIViewContentModeScaleAspectFit;

if (IS_IPHONE())
{
if (!IS_RETINA)
{
self.splashImage.image = [UIImage imageNamed:@"LaunchImage.png"];
}
else
{
if (IS_PHONEPOD5())
{
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-568h@2x.png"];
}
else
{
self.splashImage.image = [UIImage imageNamed:@"LaunchImage@2x.png"];
}
}

}
else if (IS_IPAD())
{
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait)
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
if (!IS_RETINA)
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-700-Portrait~ipad"];
else
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-700-Portrait@2x~ipad"];

}
else
{
if (!IS_RETINA)
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-Portrait~ipad"];
else
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-Portrait@2x~ipad"];
}
}
else // landscape
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
if (!IS_RETINA)
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-700-Landscape~ipad"];
else
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-700-Landscape@2x~ipad.png"];
}
else
{
if (!IS_RETINA)
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-Landscape~ipad"];
else
self.splashImage.image = [UIImage imageNamed:@"LaunchImage-Landscape@2x~ipad"];
}
}
}

where IS_IPHONE, IS_RETINA, etc. are macro defined as:

#define IS_PHONEPOD5() ([UIScreen mainScreen].bounds.size.height == 568.0f && [UIScreen mainScreen].scale == 2.f && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)   
#define IS_RETINA ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))

#define IS_IPHONE() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

Asset Catalog Launch Image Not Being Used for 4 inch simulator

Instead of using the launch image asset catalog, I created another with the same images and used that as the background image reference.

UIColor *image = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Background"]];
self.view.backgroundColor = image;

iOS 7 / Xcode 5: Access device launch images programmatically

You can use the launch images without having to include them twice. The key is that when you use an asset catalog, the file names of the images that are included in the app bundle are (sort of) standardized and may not be related to what you've named the original files.

In particular, when you use the LaunchImage image set, the files that end up in the application bundle have names like

  • LaunchImage.png
  • LaunchImage@2x.png
  • LaunchImage-700@2x.png
  • LaunchImage-568h@2x.png
  • LaunchImage-700-568h@2x.png
  • LaunchImage-700-Landscape@2x~ipad.png

etc. Note, in particular, they are not named Default.png or any variation of that. Even if that's what you called the files. Once you've dropped them in one of the wells in the asset catalog, they come out the other end with a standard name.

So [UIImage imageNamed:@"Default"] won't work because there is no such file in the app bundle. However, [UIImage imageNamed:@"LaunchImage"] will work (assuming you've filled either the iPhone Portrait 2x well or the pre iOS7 iPhone Portrait 1x well).

The documentation indicates that the imageNamed: method on UIImage should auto-magically select the correct version, but I think this only applies to image sets other than the launch image--at least I've not gotten it to work quite correctly (could just be me not doing something right).

So depending on your exact circumstances, you might need to do a little trial and error to get the correct file name. Build and run the app in the simulator and then you can always look in the appropriate subdirectory of ~/Library/Application Support/iPhone Simulator to verify what the actual file names in the app bundle are.

But again, the main point is that there is no need to include duplicates of the image files and you don't need to make any adjustments to the Copy Bundle Resources build phase.



Related Topics



Leave a reply



Submit