Xcode 5 & Asset Catalog: How to reference the LaunchImage?

前端 未结 14 1495
萌比男神i
萌比男神i 2020-11-28 18:17

I am using Xcode 5\'s Asset Catalog, and I would like to use my LaunchImage as the background image of my home view (a pretty common practice to make the transi

相关标签:
14条回答
  • 2020-11-28 18:52

    I just wrote a general method to get the splash image name for iPhone and iPad (Landscape, Portrait), It worked for me, Hope It helps you as well. I wrote this with help of other SO answers, thanks @Pichirichi for whole list.

    +(NSString*)getLaunchImageName
    {
    
     NSArray* images= @[@"LaunchImage.png", @"LaunchImage@2x.png",@"LaunchImage-700@2x.png",@"LaunchImage-568h@2x.png",@"LaunchImage-700-568h@2x.png",@"LaunchImage-700-Portrait@2x~ipad.png",@"LaunchImage-Portrait@2x~ipad.png",@"LaunchImage-700-Portrait~ipad.png",@"LaunchImage-Portrait~ipad.png",@"LaunchImage-Landscape@2x~ipad.png",@"LaunchImage-700-Landscape@2x~ipad.png",@"LaunchImage-Landscape~ipad.png",@"LaunchImage-700-Landscape~ipad.png"];
    
    UIImage *splashImage;
    
    if ([self isDeviceiPhone])
    {
        if ([self isDeviceiPhone4] && [self isDeviceRetina])
        {
            splashImage = [UIImage imageNamed:images[1]];
            if (splashImage.size.width!=0)
                return images[1];
            else
                return images[2];
        }
        else if ([self isDeviceiPhone5])
        {
            splashImage = [UIImage imageNamed:images[1]];
            if (splashImage.size.width!=0)
                return images[3];
            else
                return images[4];
        }
        else
            return images[0]; //Non-retina iPhone
    }
    else if ([[UIDevice currentDevice] orientation]==UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)//iPad Portrait
    {
        if ([self isDeviceRetina])
        {
            splashImage = [UIImage imageNamed:images[5]];
            if (splashImage.size.width!=0)
                return images[5];
            else
                return images[6];
        }
        else
        {
            splashImage = [UIImage imageNamed:images[7]];
            if (splashImage.size.width!=0)
                return images[7];
            else
                return images[8];
        }
    
    }
    else
    {
        if ([self isDeviceRetina])
        {
            splashImage = [UIImage imageNamed:images[9]];
            if (splashImage.size.width!=0)
                return images[9];
            else
                return images[10];
        }
        else
        {
            splashImage = [UIImage imageNamed:images[11]];
            if (splashImage.size.width!=0)
                return images[11];
            else
                return images[12];
        }
     }
    }
    

    Other utility methods are

    +(BOOL)isDeviceiPhone
    {
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
     {
         return TRUE;
     }
    
     return FALSE;
    }
    
    +(BOOL)isDeviceiPhone4
    {
     if ([[UIScreen mainScreen] bounds].size.height==480)
        return TRUE;
    
     return FALSE;
    }
    
    
    +(BOOL)isDeviceRetina
    {
     if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
        ([UIScreen mainScreen].scale == 2.0))        // Retina display
     {
        return TRUE;
     } 
     else                                          // non-Retina display
     {
         return FALSE;
     }
    }
    
    
    +(BOOL)isDeviceiPhone5
    {
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && [[UIScreen mainScreen] bounds].size.height>480)
     {
        return TRUE;
     }
     return FALSE;
    }
    
    0 讨论(0)
  • 2020-11-28 18:55

    This is the (almost) complete list of the LaunchImage (excluding the iPad images with no status bar):

    • LaunchImage-568h@2x.png
    • LaunchImage-700-568h@2x.png
    • LaunchImage-700-Landscape@2x~ipad.png
    • LaunchImage-700-Landscape~ipad.png
    • LaunchImage-700-Portrait@2x~ipad.png
    • LaunchImage-700-Portrait~ipad.png
    • LaunchImage-700@2x.png
    • LaunchImage-Landscape@2x~ipad.png
    • LaunchImage-Landscape~ipad.png
    • LaunchImage-Portrait@2x~ipad.png
    • LaunchImage-Portrait~ipad.png
    • LaunchImage.png
    • LaunchImage@2x.png
    • LaunchImage-800-667h@2x.png (iPhone 6)
    • LaunchImage-800-Portrait-736h@3x.png (iPhone 6 Plus Portrait)
    • LaunchImage-800-Landscape-736h@3x.png (iPhone 6 Plus Landscape)
    • LaunchImage-1100-Portrait-2436h@3x.png (iPhone X Portrait)
    • LaunchImage-1100-Landscape-2436h@3x.png (iPhone X Landscape)
    0 讨论(0)
提交回复
热议问题