iOS截取LaunchScreen.storyboard图片
2020-04-04 本文已影响0人
整个夏天
代码
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以及全面屏