1、在图片文件夹Assets.xcassets左侧创建New Image Set,名字自己定
2、右键创建的文件点击Show in Finder
3、找到新建文件下的contents.json文件
4、复制以下内容替换原cotents.json内容并保存
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "splash_bgXSMax@3x.png",
"idiom" : "universal",
"scale" : "3x"
},
{
"filename" : "splash_bg.png",
"idiom" : "iphone",
"scale" : "1x",
"subtype" : "retina4"
},
{
"filename" : "splash_bg@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"subtype" : "retina4"
},
{
"filename" : "splash_bg@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"subtype" : "retina4"
},
{
"filename" : "splash_bg55@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"subtype" : "736h"
},
{
"filename" : "splash_bg47@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"subtype" : "667h"
},
{
"filename" : "splash_bgXS@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"subtype" : "2436h"
},
{
"filename" : "splash_bgXSMax@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"subtype" : "2688h"
},
{
"filename" : "splash_bgXR@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"subtype" : "1792h"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
5、回到项目工程中,点击刚才创建的New Image Set会发现对应的图片规格,由于iPhone12目前没有规格,因此在universal中添加对应尺寸的3x图即可对应通用适配
注意:添加完图片后,删除项目,关闭模拟器,clean一下Xcode,然后重新运行项目即可