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