4

I'm using LaunchImage.launchimage in Images.xcassets to manage the launch images. But I'm trying to use the launch images inside the app also.

I've read this answer :

The documentation indicates that the imageNamed: method on UIImage should auto-magically select the correct version

So, I used this code

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

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

So how can I access the correct LaunchImage of iPad programatically ??

The contents of Contents.json 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"
  }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
MujtabaFR
  • 5,956
  • 6
  • 40
  • 66

3 Answers3

2

I've solved this issue 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"];
        }
    }
}
MujtabaFR
  • 5,956
  • 6
  • 40
  • 66
0

I believe that those extensions (-700-Landscape@2x~ipad for example) are not recognisable.

Add the following item to your Contents.json just for testing purpose:

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

Now try the imageNamed: method.

Or try the imageNamed: with the image full name:

backImage.image = [UIImage imageNamed:@"LaunchImage-700-Landscape~ipad.png"];
hasan
  • 23,815
  • 10
  • 63
  • 101
  • if this didn't your too. you need to get the Images.xcassets bundle. please confirm. I will add the code that gets Images.xcassets bundle. – hasan Aug 09 '15 at 08:57
  • Sorry.. event after renaming `LaunchImage-700-Portrait~ipad.png` to `LaunchImage.png` and editing the `Contents.json`, nothing changed and still returning iPhone 4s image – MujtabaFR Aug 09 '15 at 13:16
  • But when using full image name like this `[UIImage imageNamed:@"LaunchImage-700-Landscape~ipad.png"]` it works.. but that will need much more codes to work well – MujtabaFR Aug 09 '15 at 13:18
  • I know. Thats never worked for me too. I believe that apple never rly supported this 100% for all these extensions. Only some works. The simple ones as @2x only – hasan Aug 09 '15 at 13:21
0

LaunchImage.launchimage

Are you really using Images.xcassets to manage the launch images? Aren't you using LaunchImage.launchimage instead?

If so, there comes the confusion. You cannot load 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 is not in that list.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • Yes, I'm using `LaunchImage.launchimage` which is inside `Images.xcassets` – MujtabaFR Aug 09 '15 at 13:20
  • 1
    Even after renaming `LaunchImage-700-Portrait~ipad.png` to `LaunchImage-700~ipad.png` and editing the Contents.json, nothing changed and still returning iPhone 4s launch image – MujtabaFR Aug 09 '15 at 13:21