iOS 获取启动图截图

+ (UIImage *)getLaunchImage {
    UIImage *image = nil;
    CGSize viewSize = [[UIScreen mainScreen] bounds].size;
    NSString *viewOrientation = @"Portrait";    //横屏请设置成 @"Landscape"
    NSString *launchImage = nil;
    //1.通过launchimage获取
    NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for (NSDictionary* dict in imagesDict) {
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
            launchImage = dict[@"UILaunchImageName"];
            image = [UIImage imageNamed:launchImage];
        }
    }
    if (!image) {
        //加载指定启动图
        image = [UIImage imageNamed:@"LaunchImage-xxx(自定义图片)"];
    }
//2.通过launchscreen.storyboard获取
   if (!image) {
        //拿到LaunchScreen.StoryBoard并生成一个控制器
  NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *storyboardName = [infoDic valueForKey:@"UILaunchStoryboardName"];
    if (storyboardName.length>0) {
        // 转换为UIImage
    CGRect frame = [UIScreen mainScreen].bounds;
    UIView *view = vc.view;
    UIGraphicsBeginImageContext(frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
  }
    }
    return image;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容