简体   繁体   中英

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

As suggested here , in Interface Builder i've assigned to a full size Image View the "LaunchImage.png" parameter for the "Image" attribute, being associated at runtime by iOS .

在此输入图像描述

But at runtime, in any device (iPhone, iPad, with/without retina), the image picked is always the 640 × 960 pixels size image, thus ignoring other sizes.

Is there any way to make iOS automatically picking the right image base on device and resolution?

Yes there is an easier way to do this in XCode 5.

  1. Click on your Xcode General Tab
  2. Then scroll below and look for Launch images. See the little gray arrow click that
  3. You can now drag and drop launch images for specific devices.
  4. You can also select different launch images between iOS6 & iOS7 devices if you so choose.
  5. Correct launch images will be picked up automatically for each device and screens size.

See these screenshots.

在此输入图像描述在此输入图像描述在此输入图像描述

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM