Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5.1 and Default.png

Tags:

ios

ipad

ios5

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?

like image 602
mobius Avatar asked Apr 12 '12 11:04

mobius


2 Answers

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"]; 
like image 139
Rok Jarc Avatar answered Sep 22 '22 03:09

Rok Jarc


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];
like image 2
cleverbit Avatar answered Sep 22 '22 03:09

cleverbit