0

有没有办法将启动图像作为当前设备的 UIImage 获取?或带有图像的 UIImageView

4

3 回答 3

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];
    }
}
于 2013-08-18T11:33:59.273 回答
0

[UIDevice currentDevice]首先使用然后减少启动图像的名称,[UIScreen mainScreen]然后像读取任何其他资源图像一样读取图像。

[UIImage imageNamed:yourLaunchedImageName];
于 2013-08-18T11:20:16.083 回答
0

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

- (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];
}
于 2014-10-20T12:51:22.977 回答