I am developing an application using iOS 5.1 and I am experiencing some strange behavior with the default.png files.
I have added the following files to my application:
Default.png - (iPhone)
[email protected] - (iPhone Retina)
Default-Portrait~ipad.png - (iPad)
Default-Portrait@2x~ipad.png -(iPad Retina)
When the application starts it seems that it selects the correct Default.png image to use for each occasion. However in my AppDelegate I have a simple splash screen to make smoother the loading of the application and the transition to the app, doing something like:
UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,window.frame.size.width, window.frame.size.height)];
splashView.image = [UIImage imageNamed:@"Default"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
However the [UIImage imageNamed:@"Default"]
in turn does not select the correct file for each device, and I believe the problem is the -Portrait
part of the filename.
So as a quick solution I did this:
if( ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ) {
// Force the image used by ipads
if( [[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0) {
splashView.image = [UIImage imageNamed:@"Default-Portrait@2x~ipad"];
}
else {
splashView.image = [UIImage imageNamed:@"Default-Portrait~ipad"];
}
}
else
splashView.image = [UIImage imageNamed:@"Default"];
Is this how I should be doing this? Does this look funny to you?
For official information here take a look at: App-Related Resources
For Launch images use this format:
<basename><orientation_modifier><scale_modifier><device_modifier>.png
It looks you would be better off using:
Default.png - (iPad)
[email protected] - (iPad Retina)
Default~iphone.png - (iPhone)
Default@2x~iphone.png -(iPhone Retina)
This should give you proper image even if using simply:
splashView.image = [UIImage imageNamed:@"Default"];
Once my Universal app has finished loading, I display a copy of the launch screen in a UIImageView
and then fade it out, to give a gentle transition between launching and the app being ready. Here's the code that I use in order to determine which image to use:
// choose the correct launch image for orientation, device and scale
NSMutableString *launchImageName = [[NSMutableString alloc] initWithString:@"Default"];
BOOL isPad = ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad );
if( isPad )
{
BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
NSString *imageOrientation = (isLandscape) ? @"Landscape" : @"Portrait";
BOOL isRetina = ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0);
NSString *scaleString = (isRetina) ? @"@2x" : @"";
// Default-Landscape~ipad.png
// Default-Landscape@2x~ipad.png
// Default-Portrait~ipad.png
// Default-Portrait@2x~ipad.png
launchImageName = [NSMutableString stringWithFormat:@"%@-%@%@~ipad.png", launchImageName, imageOrientation, scaleString ];
} else {
if( CGRectGetHeight(self.view.frame) > 480.f)
{
// Default-568h.png
launchImageName = [NSMutableString stringWithFormat:@"%@-568h.png", launchImageName];
} else {
// Default.png
// [email protected]
launchImageName = [NSMutableString stringWithFormat:@"%@.png", launchImageName];
}
}
UIImage *launchImage = [UIImage imageNamed:launchImageName];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With