iOS启动图片尺寸及适配

1、在图片文件夹Assets.xcassets左侧创建New Image Set,名字自己定

截屏2021-07-21 09.00.47.png

2、右键创建的文件点击Show in Finder

截屏2021-07-21 09.00.58.png

3、找到新建文件下的contents.json文件

截屏2021-07-21 09.02.06.png

4、复制以下内容替换原cotents.json内容并保存


{
  "images" : [
    {
      "idiom" : "universal",
      "scale" : "1x"
    },
    {
      "idiom" : "universal",
      "scale" : "2x"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "universal",
      "scale" : "3x"
    },
    {
      "filename" : "splash_bg.png",
      "idiom" : "iphone",
      "scale" : "1x",
      "subtype" : "retina4"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "iphone",
      "scale" : "2x",
      "subtype" : "retina4"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "iphone",
      "scale" : "3x",
      "subtype" : "retina4"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "iphone",
      "scale" : "3x",
      "subtype" : "736h"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "iphone",
      "scale" : "2x",
      "subtype" : "667h"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "iphone",
      "scale" : "3x",
      "subtype" : "2436h"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "iphone",
      "scale" : "3x",
      "subtype" : "2688h"
    },
    {
      "filename" : "[email protected]",
      "idiom" : "iphone",
      "scale" : "2x",
      "subtype" : "1792h"
    }
  ],
  "info" : {
    "author" : "xcode",
    "version" : 1
  }
}

5、回到项目工程中,点击刚才创建的New Image Set会发现对应的图片规格,由于iPhone12目前没有规格,因此在universal中添加对应尺寸的3x图即可对应通用适配

截屏2021-07-21 09.11.09.png

注意:添加完图片后,删除项目,关闭模拟器,clean一下Xcode,然后重新运行项目即可

你可能感兴趣的:(iOS启动图片尺寸及适配)