IOS UIImage of launch image for current device
Asked Answered
P

3

0

is there way to get launch image as UIImage for current device? or UIImageView with an image

Preinstruct answered 18/8, 2013 at 11:15 Comment(0)
S
3

You just need to get Default.png which will have any @2x applied as necessary.

- (UIImage *)splashImage {
    return [UIImage imageNamed:@"Default.png"];
}

If you care about getting the iPhone 5 specific one you need to do a height check:

- (UIImage *)splashImage {
    if ([[UIScreen mainScreen] bounds].size.height == 568.0){
        return [UIImage imageNamed:@"Default-568h.png"];
    } else {
        return [UIImage imageNamed:name];
    }
}
Subversion answered 18/8, 2013 at 11:33 Comment(2)
well, if there is no another way to do it, this is oK,Preinstruct
This will not help you when you are on an iPad.Yance
J
0

First reduce the name of the launch image using [UIDevice currentDevice] and [UIScreen mainScreen] and then read the image like you would for any other resource image.

[UIImage imageNamed:yourLaunchedImageName];
Jackboot answered 18/8, 2013 at 11:20 Comment(0)
B
0

You can write something like this.
Here we are figuring out what splash image to show (depending on device and scree rotation) and adding it as a subview to our window.

- (void)showSplashImage
{
    NSString *imageSuffix = nil;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        imageSuffix = [[UIScreen mainScreen] bounds].size.height >= 568.0f ? @"-568h@2x" : @"@2x";
    }
    else
    {
        UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
        imageSuffix = UIInterfaceOrientationIsPortrait(orientation) ? @"Portrait" : @"-Landscape";
        imageSuffix = [UIScreen mainScreen].scale == 2.0 ? [imageSuffix stringByAppendingString:@"@2x~ipad"] : [imageSuffix stringByAppendingString:@"~ipad"];
    }

    NSString *launchImageName = [NSString stringWithFormat:@"Default%@.png",imageSuffix];

    NSMutableString *path = [[NSMutableString alloc]init];
    [path setString:[[NSBundle mainBundle] resourcePath]];
    [path setString:[path stringByAppendingPathComponent:launchImageName]];

    UIImage * splashImage = [[UIImage alloc] initWithContentsOfFile:path];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:splashImage];
    imageView.tag = 2;
    [self.rootViewController.view addSubview:imageView];
}
Bluegrass answered 20/10, 2014 at 12:51 Comment(2)
This seems overly complicated for something so simple, also not sure how this adds to all the other answers except for adding more code.Apollyon
It also has the fragility of not dealing with @3x, or whatever comes next.Augur

© 2022 - 2024 — McMap. All rights reserved.