问题
is there way to get launch image as UIImage for current device? or UIImageView with an image
回答1:
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];
}
}
回答2:
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];
回答3:
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];
}
来源:https://stackoverflow.com/questions/18298477/ios-uiimage-of-launch-image-for-current-device