is there way to get launch image as UIImage for current device? or UIImageView with an image
Asked
Active
Viewed 1,864 times
3 Answers
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];
}
}

Mike Kwan
- 24,123
- 12
- 63
- 96
-
well, if there is no another way to do it, this is oK, – user840250 Aug 18 '13 at 11:34
-
2This will not help you when you are on an iPad. – ullstrm Nov 14 '13 at 10:13
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];

Buntylm
- 7,345
- 1
- 31
- 51

Jerome Diaz
- 1,746
- 8
- 15
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];
}

Temak
- 2,929
- 36
- 49
-
This seems overly complicated for something so simple, also not sure how this adds to all the other answers except for adding more code. – Popeye Oct 20 '14 at 14:37
-
It also has the fragility of not dealing with @3x, or whatever comes next. – Olie Feb 27 '15 at 00:20