0
votes

I'm writing a universal app that supports rotation. When app starts, it needs to download some data from internet, so I push a UIViewController with activity indicator, because it is not possible to have animated launch images or add labels or objects to it.

I would like the "loading" VC has the same bg image as launch, but, because it is a universal app, I can't set a simple [UIImage imageNamed:@"Default.png"] because it can running on iPhone or iPad and if iPad can be launched in portrait or landscape (iPhone apps always start in portrait).

The question is: there's a way to know which Default.png has been used as launch image? it can be

  • Default.png (@2x if retina)
  • Default-Portrait.png (@2x if retina)
  • Default-Landscape.png (@2x if retina)
  • [email protected]

If there's now way, I will check currentDevice and orientation and set imageNamed manually.

Thanks, Max

2

2 Answers

1
votes

There is no suffix for portrait and landscape. You will have to check the orientation manually with [[UIDevice currentDevice] orientation].

For showing different images for the iPad and iPhone/iPod Touch, you can add ~ipad onto the end of the iPad image and ~iphone onto the end of the iPhone/iPod Touch image. Example:

Default~iphone.png will load on iPhone/iPod Touch and Default~ipad.png will load on iPad with this:

[UIImage imageNamed:@"Default.png"];

There is also no specifier for iPhone 5 though. So you will have to check [[UIScreen mainScreen] bounds].size.height and again load the UIImage manually.


FULL (untested) EXAMPLE:

UIImage *image;

if ([UIScreen mainScreen].bounds.size.height == 568.0)
{
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
    {
        image = [UIImage imageNamed:@"Default-568h-Landscape"];
    }
    else
    {
        image = [UIImage imageNamed:@"Default-568h-Portrait"];
    }
}
else
{
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
    {
        image = [UIImage imageNamed:@"Default-Landscape"];
    }
    else
    {
        image = [UIImage imageNamed:@"Default-Portrait"];
    }
}
// check suggested by Guy Kogus
if (image == nil) image = [UIImage imageNamed:@"Default"];

To answer your question in the comments:

No, you cannot query what launch image was used at runtime.

0
votes

The @2x suffix is automatically chosen, so you don't need to worry about that. There are a few checks that you need to implement:

- (NSString *)defaultImage
{
    NSString *imageName = nil;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        if ([UIScreen mainScreen].bounds.size.height == 568.0)
        {
            imageName = @"Default-568h";
        }
        else
        {
            imageName = @"Default";
        }
    }
    else // ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
        {
            imageName = @"Default-Landscape";
        }
        else // if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
        {
            imageName = @"Default-Portrait";
        }
    }
    return [UIImage imageNamed:imageName];
}