iOS截取LaunchScreen.storyboard图片
作者:
整个夏天 | 来源:发表于
2020-04-04 16:33 被阅读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以及全面屏
本文标题:iOS截取LaunchScreen.storyboard图片
本文链接:https://www.haomeiwen.com/subject/ajpjphtx.html
网友评论