Access to iPad launch software programmatically?

I am using LaunchImage.launchimage in Images.xcassets to manage startup images. But I'm also trying to use startup images inside the application.

I read this answer :

The documentation indicates that the imageNamed: method on UIImage should automatically-magical select the correct version

So, I used this code

 UIImageView *backImage = [UIImageView new]; backImage.image = [UIImage imageNamed:@"LaunchImage"]; 

When working on the iPhone 4,5,6,6+, it works fine and gets the correct LaunchImage, but when working with the iPad's retina, it returns LaunchImage-700@2x.png , which is LaunchImage iPhone 4s 640 x 960 pixels

So, how can I access the correct LaunchImage iPad programmatically?

Contents.json content in LaunchImage folder

 { "images" : [ { "extent" : "full-screen", "idiom" : "iphone", "subtype" : "736h", "filename" : " LaunchImage-800-Portrait-736h@3x.png ", "minimum-system-version" : "8.0", "orientation" : "portrait", "scale" : "3x" }, { "extent" : "full-screen", "idiom" : "iphone", "subtype" : "667h", "filename" : " LaunchImage-800-667h@2x.png ", "minimum-system-version" : "8.0", "orientation" : "portrait", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "iphone", "extent" : "full-screen", "minimum-system-version" : "7.0", "filename" : " LaunchImage-700@2x.png ", "scale" : "2x" }, { "extent" : "full-screen", "idiom" : "iphone", "subtype" : "retina4", "filename" : " LaunchImage-700-568h@2x.png ", "minimum-system-version" : "7.0", "orientation" : "portrait", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "ipad", "extent" : "full-screen", "minimum-system-version" : "7.0", "filename" : "LaunchImage-700-Portrait~ipad.png", "scale" : "1x" }, { "orientation" : "landscape", "idiom" : "ipad", "extent" : "full-screen", "minimum-system-version" : "7.0", "filename" : "LaunchImage-700-Landscape~ipad.png", "scale" : "1x" }, { "orientation" : "portrait", "idiom" : "ipad", "extent" : "full-screen", "minimum-system-version" : "7.0", "filename" : " LaunchImage-700-Portrait@2x ~ipad.png", "scale" : "2x" }, { "orientation" : "landscape", "idiom" : "ipad", "extent" : "full-screen", "minimum-system-version" : "7.0", "filename" : " LaunchImage-700-Landscape@2x ~ipad.png", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "iphone", "extent" : "full-screen", "filename" : "LaunchImage-700.png", "scale" : "1x" }, { "orientation" : "portrait", "idiom" : "iphone", "extent" : "full-screen", "filename" : " LaunchImage-700@2x.png ", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "iphone", "extent" : "full-screen", "filename" : " LaunchImage-700-568h@2x.png ", "subtype" : "retina4", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "ipad", "extent" : "full-screen", "filename" : "LaunchImage-700-Portrait~ipad.png", "scale" : "1x" }, { "orientation" : "landscape", "idiom" : "ipad", "extent" : "full-screen", "filename" : "LaunchImage-700-Landscape~ipad.png", "scale" : "1x" }, { "orientation" : "portrait", "idiom" : "ipad", "extent" : "full-screen", "filename" : " LaunchImage-700-Portrait@2x ~ipad.png", "scale" : "2x" }, { "orientation" : "landscape", "idiom" : "ipad", "extent" : "full-screen", "filename" : " LaunchImage-700-Landscape@2x ~ipad.png", "scale" : "2x" } ], "info" : { "version" : 1, "author" : "xcode" } } 

Thanks in advance.

+4
source share
3 answers

I solved this problem using a long method

 BOOL deviceIsIpad = NO; if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) { deviceIsIpad = YES; } if (!deviceIsIpad) { backImage.image = [UIImage imageNamed:@"LaunchImage"]; } else { UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; CGFloat screenScale = [[UIScreen mainScreen] scale]; if (interfaceOrientation == UIDeviceOrientationPortrait || interfaceOrientation == UIDeviceOrientationPortraitUpsideDown){ if (screenScale > 1) { backImage.image = [UIImage imageNamed:@" LaunchImage-700-Portrait@2x ~ipad.png"]; } else { backImage.image = [UIImage imageNamed:@"LaunchImage-700-Portrait~ipad.png"]; } } else { if (screenScale > 1) { backImage.image = [UIImage imageNamed:@" LaunchImage-700-Landscape@2x ~ipad.png"]; } else { backImage.image = [UIImage imageNamed:@"LaunchImage-700-Landscape~ipad.png"]; } } } 
+2
source

I believe that these extensions (-700-Landscape @ 2x ~ ipad, for example) are not recognized.

Add the following element to your Content.json for testing purposes only:

 { "orientation" : "landscape", "idiom" : "ipad", "extent" : "full-screen", "filename" : "LaunchImage.png", "scale" : "1x" } 

Now try the imageNamed: method.

Or try imageNamed: with the full image name:

 backImage.image = [UIImage imageNamed:@"LaunchImage-700-Landscape~ipad.png"]; 
0
source

LaunchImage.launchimage

Do you Images.xcassets to manage startup snapshots? You are not using LaunchImage.launchimage instead?

If so, there is confusion. You cannot upload using [UIImage imageNamed:@"LaunchImage"]; from LaunchImage.launchimage .

Canonical names

  • LaunchImage.png
  • LaunchImage@2x.png
  • LaunchImage-700@2x.png
  • LaunchImage-568h@2x.png
  • LaunchImage-700-568h@2x.png
  • LaunchImage-700-Landscape@2x ~ipad.png

LaunchImage-700- Portrait @2x~ipad.png not on this list.

0
source

All Articles