iOS截取LaunchScreen.storyboard图片

代码

UIViewController * vc = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
CGRect rect = [UIScreen mainScreen].bounds;
UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
vc.view.frame = rect;
[vc.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

注意事项

  1. storyboard的背景图片设置上下约束的时候的对象是superView,而不是Top Layout Guidebottom Layout Guide
  2. 设置约束的时候取消Constrain to margins
  3. vc.view.frame = rect;这里要根据屏幕大小设置一下view的大小,因为如果storyboard是根据iPhone8的屏幕制作的,那么此时view的大小无法满足plus以及全面屏
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。