IOS UIImage当前设备的启动图像

时间:2013-08-18 11:15:14

标签: ios cocoa uiimageview uidevice

是否可以将启动图像作为当前设备的UIImage? 或带有图像的UIImageView

3 个答案:

答案 0 :(得分:3)

您只需要Default.png获得必要的@2x

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

如果你想要获得iPhone 5特定的一个,你需要进行高度检查:

- (UIImage *)splashImage {
    if ([[UIScreen mainScreen] bounds].size.height == 568.0){
        return [UIImage imageNamed:@"Default-568h.png"];
    } else {
        return [UIImage imageNamed:name];
    }
}

答案 1 :(得分:0)

首先使用[UIDevice currentDevice][UIScreen mainScreen]缩小启动图像的名称,然后像对待任何其他资源图像一样阅读图像。

[UIImage imageNamed:yourLaunchedImageName];

答案 2 :(得分:0)

你可以写这样的东西 在这里,我们要弄清楚要显示的启动图像(取决于设备和scree旋转)并将其作为子视图添加到我们的窗口。

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