美文网首页iOS
iOS启动图片尺寸及适配

iOS启动图片尺寸及适配

作者: mqw | 来源:发表于2021-07-21 09:18 被阅读0次

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" : "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图即可对应通用适配

截屏2021-07-21 09.11.09.png

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

相关文章

网友评论

    本文标题:iOS启动图片尺寸及适配

    本文链接:https://www.haomeiwen.com/subject/nnndmltx.html