6

Xcode's default Images.xcassets file has a slot for LaunchImage, where for a portrait iPhone app there are 5 possible slots.

According to the documentation, to get an image properly sized from the xcassets file, just use [UIImage imageNamed:].

However, running the following code on iPhone Retine (4-inch) simulator:

UIImage *splashImage = [UIImage imageNamed:@"LaunchImage"];
NSLog(@"%@", NSStringFromCGSize(splashImage.size));

produces the following output:

{320, 480}

which is obviously the wrong size.

I have made sure that the mappings in the xcassets file are correct, and have confirmed all dimensions. It also seems that I cannot request a specific image from a given set in the xcassets file, meaning I cannot do:[UIImage imageNamed:@"LaunchImageR4"].

And since the files are added to an xcassets file, I also do not have access to the raw image files, so a custom solution seems out of the question.

Does anyone have any idea how I would solve this issue?

Snowman
  • 31,411
  • 46
  • 180
  • 303

2 Answers2

-1

I believe that the correct launch image is loaded automatically at startup. It is not meant to be pulled from xcassets during runtime. Since it is at runtime, you will have to do your own check for which device is being used, as the image catalog is only setup to pull retina vs. non-retina using the @2x postfix (not the size of the device).

You can use this post to determine which device is being used and load the correct image by name.

Community
  • 1
  • 1
timgcarlson
  • 3,017
  • 25
  • 52
  • Yes but I do not have access to the raw launch image files. My launch image files are called `AppSplash.png`, but if I were to access that with UIImage, it would come up empty. Therefore your solution would not work. – Snowman Dec 09 '13 at 18:05
-1

Launch images are a special kind of image set. You can't use [UIImage imageNamed:@"LaunchImage"] to get the correct launch image that suits your device (i.e. iPhone 3", 4" or iPad + Retina).

Guy Kogus
  • 7,251
  • 1
  • 27
  • 32
  • 1
    I don't understand what your answer is saying. You're just telling me that I can't? – Snowman Dec 09 '13 at 18:05
  • Not using `imageNamed:` If you want to know if you're on a 4" display then just check if `[UIScreen mainScreen].bounds.size.height == 568.0f` and then you'll have to manually select the right image. – Guy Kogus Dec 10 '13 at 09:50
  • This is not an answer and is not useful. This provides no solution, nor citation, nor explanation. – Ky - Apr 24 '19 at 19:59
  • I understand that this may have not been useful to you @BenLeggiero, but please watch the tone that you use here. I recommend reading the StackOverflow code of conduct: https://stackoverflow.com/conduct – Guy Kogus Apr 25 '19 at 10:01
  • Thank you for the reminder, @GuyKogus. What I meant by that was that this post points out a problem, but it offers no solution; some suggestion of how to properly address the question, as well as explanation for why you saw this as the problem at-hand, would fix that. Additionally, it makes the claim _"You can't use `[UIImage imageNamed:@"LaunchImage"]` to get the correct launch image that suits your device"_, but provides no evidence to back up that claim; some links to Apple documentation would fix that. I am saying this in the spirit of having high-quality answers on StackOverflow. – Ky - Apr 25 '19 at 15:44
  • Additionally, @GuyKogus, I'm unaware that my comment goes against the code of conduct. Could you help me learn how to better phrase it, so that I keep myself rooted in kindness, collaboration, and mutual respect? – Ky - Apr 25 '19 at 15:45
  • 1
    @BenLeggiero your original comment comes across as a bit aggressive. If you look at the CoC link I posted it will show you examples of what kind of messages are considered "unfriendly" vs "friendly". Yours would be in the "unfriendly" category, whereas a "friendly" response would've been more in the lines of, "I believe that this answer would be clearer and more benificial if you provided an actual solution or more in-depth explanation." Hope that helps :) – Guy Kogus Apr 25 '19 at 15:52
  • Good points. Thanks! I'll be more careful in the future – Ky - Apr 27 '19 at 02:40