以编程方式加载启动图像

时间:2015-03-18 06:15:39

标签: ios xcode

现在,看起来必须为构建设置中的“启动屏幕文件”字段设置启动图像文件名(例如launchimage.xib),以便显示launchimage.xib。是否可以改为:

  • 动态加载启动图像和/或
  • 将操作与启动图像相关联?

2 个答案:

答案 0 :(得分:8)

我认为无法动态加载启动图像。但是,您可以使用以下代码访问已添加到应用程序中的启动图像。您也可以检查它是否与您的设备规模和尺寸相匹配。

NSArray *allPngImageNames = [[NSBundle mainBundle] pathsForResourcesOfType:@"png"
                                    inDirectory:nil];

for (NSString *imgName in allPngImageNames){
// Find launch images
if ([imgName containsString:@"LaunchImage"]){
    UIImage *img = [UIImage imageNamed:imgName]; //-- this is a launch image

    // Has image same scale and dimensions as our current device's screen?
    if (img.scale == [UIScreen mainScreen].scale && CGSizeEqualToSize(img.size, [UIScreen mainScreen].bounds.size)) {
        NSLog(@"Found launch image for current device %@", img.description);
    }
  }
}

但是我不相信这会对你有所帮助

答案 1 :(得分:1)

启动图像(或故事板)由应用启动器处理,而不是由应用本身处理。因此,我认为无法加载动态启动图像或附加操作。除了使用故事板或静态图像之外,https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/launch-screen/处的文档不会为您的启动屏幕提供任何选项。

相关问题