以编程方式加载启动图像

3

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

  • 动态加载启动图像,和/或
  • 将操作与启动图像关联?
2个回答

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);
    }
  }
}

然而,我并不认为这会对你有很大帮助。

谢谢@Ganesh---我正在寻找动态启动选项,即如果将文件名传递给应用程序,则应加载该filename.xib而不是默认的启动图像。 - NSCoder
这在程序上是不可能的。还有其他类似答案的问题,例如https://dev59.com/2VrUa4cB1Zd3GeqPgyG_和http://stackoverflow.com/questions/23637378/can-i-choose-my-launch-image-programmatically。 - Ganesh Somani

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接