使用LaunchScreen.storyboard搭建启动图
首先,要在项目中进行配置。
1、在General—> App Icons and Launch Images—>Launch Screen File中选择LaunchScreen

2、选中LaunchScreen.storyboard,勾选Use as Launch Screen的选项

3、在LaunchScreen.storyboard中添加一个UIImageView的控件

4、为新添加的UIImageView添加约束

5、设置约束
选中上下左右的约束(点击短横线),并将数值都设为0,最后点击Add按钮,如下图所示

6、修改约束
经过步骤5之后,效果如下:

从上图可以看出,默认的Safe Area会在iPhoneX系列的机型上,使启动图没有覆盖整个屏幕。
7、解决留白问题
在左窗口选中底部约束—>点击右侧的First item—>选择Superview—>将Constant设置为0,如下所示:

修改完成的效果如下:

然后再修改top上的约束

修改完后的效果:

8.在项目的根目录里创建一个文件夹(launchImage),然后找设计要一张1242*2208 的启动图,(命名为xxxx@3x.png),添加到刚创建的文件夹(launchImage)里
9.给 7.3步骤里的imageView 添加 8 步骤里的(xxxx@3x.png) 图片,并设置Content Mode : Aspect Fill

10.然后启动就OK了,以后更换图片 只需要更换 步骤 8 里的图片就好了,如果遇到不生效的问题,删除app ,clean项目,重启手机.
参考链接 : https://www.jianshu.com/p/1d1ae1dd0a71
网友评论