首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当前设备发射图像的IOS UIImage

当前设备发射图像的IOS UIImage
EN

Stack Overflow用户
提问于 2013-08-18 11:15:13
回答 3查看 1.9K关注 0票数 0

是否有方法以UIImage的方式获得当前设备的启动映像?或带有图像的UIImageView

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-08-18 11:33:59

您只需要获得Default.png,它将在必要时应用任何@2x

代码语言:javascript
复制
- (UIImage *)splashImage {
    return [UIImage imageNamed:@"Default.png"];
}

如果您关心的是获得iPhone 5特定的一个,您需要做一个高度检查:

代码语言:javascript
复制
- (UIImage *)splashImage {
    if ([[UIScreen mainScreen] bounds].size.height == 568.0){
        return [UIImage imageNamed:@"Default-568h.png"];
    } else {
        return [UIImage imageNamed:name];
    }
}
票数 3
EN

Stack Overflow用户

发布于 2013-08-18 11:20:16

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

代码语言:javascript
复制
[UIImage imageNamed:yourLaunchedImageName];
票数 0
EN

Stack Overflow用户

发布于 2014-10-20 12:51:22

你可以写这样的东西。

在这里,我们正在找出什么飞溅图像显示(取决于设备和屏幕旋转),并把它作为一个子视图到我们的窗口。

代码语言:javascript
复制
- (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];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18298477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档