IOS UIImage of launch image for current device

点点圈 提交于 2019-12-12 03:12:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!