Question

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

Était-ce utile?

La solution

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];
    }
}

Autres conseils

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];

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];
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top