0

I'm accessing LaunchImage by [UIImage imageNamed:@"LaunchImage"] but it always gives me 640x960 no matter what. It obviously does not seem to detect which phone I'm using and it just throws 640x960.

I could check for the screen size and set specific image names for each device but that's not really ideal. There must be a simple way to just get this done. Does anyone know?

Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156
durazno
  • 559
  • 2
  • 7
  • 25
  • try http://stackoverflow.com/questions/32062621/launchimage-does-not-work-for-iphone4s-in-newest-xcode?rq=1 – sschale May 27 '16 at 04:20
  • I think you didn't even get what my problem is.. I'm asking how to easily access launch images for each device programmatically without having to check for screen sizes. – durazno May 27 '16 at 04:24
  • Found a blog about this "problem" and turns out it is impossible. Deleting this question soon. – durazno May 27 '16 at 04:30
  • wouldn't manually adding image to launch screen and performing auto layout help? @durazno – Akshansh Thakur May 27 '16 at 04:32
  • You're not listening to me.. that's already been done and I was asking something else. Really should've deleted this question sooner now I can't cuz some others have posted nonsensical answers.. – durazno May 27 '16 at 14:30

2 Answers2

0

The key to this is that the Info.plist file contains information on which splash image to use. This method below will find that name from the Info.plist, and then you'll just have to query it from [UIImage imageNamed:@""] method.

- (NSString *)splashImageNameForOrientation:(UIInterfaceOrientation)orientation {
    CGSize viewSize = self.view.bounds.size;
    NSString* viewOrientation = @"Portrait";
    if (UIDeviceOrientationIsLandscape(orientation)) {
        viewSize = CGSizeMake(viewSize.height, viewSize.width);
        viewOrientation = @"Landscape";
    }

    NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for (NSDictionary* dict in imagesDict) {
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]])
            return dict[@"UILaunchImageName"];
    }

    if (imagesDict.count > 0) {
        return [imagesDict firstObject][@"UILaunchImageName"];
    }
    return nil;
}
Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156
  • Why are you giving me this answer when I'd already specifically mentioned that I do know how. I just wanted to know if it was possible to do it WITHOUT having to check which device is being used. – durazno May 27 '16 at 14:29
  • Why can't we check for the size again? – Enrico Susatyo May 27 '16 at 15:48
  • Have you still not read my question..? I never said we couldn't we absolutely can and I know how. I said very clearly that I was looking for a way to skip that part if possible. The answer is we can't. – durazno May 28 '16 at 03:26
0

Refer this url:

Launch screens supporting iOS6 and iOS7 - forced to splash screen

or

you are add Launch Screen in Assets.xcassets: you are see image size as below image:

enter image description here

Community
  • 1
  • 1
Bhadresh Kathiriya
  • 3,147
  • 2
  • 21
  • 41