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" : "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,然后重新运行项目即可

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容