gpt4 book ai didi

ios - 我应该使用 xcassets 还是只更改一张图像的大小以在 iOS 的多个设备上开发?

转载 作者:行者123 更新时间:2023-11-29 01:40:48 27 4
gpt4 key购买 nike

我想在我的 UICollectionView 上显示占位符图像,直到单元格从我的服务器获取图像。但是,我想知道我是否应该为 Images.xcassests 中的情况 1x、2x 和 3x 提前准备三张不同的图像,或者只准备一个 SVG 文件并在图像加载后处理它的大小代码。

具体来说,如果您采用第一种方法,您的过程是这样的:

let imageView = UIImageView(image: UIImage(named: "PlaceholderImageInXcassets")) // frame is set to the size of the image automatically
self.view.addSubview(imageView)

这是第二种方法:

let imageView = UIImageView(image: UIImage(named: "PlaceholderImage"))
imageView.frame = CGRectMake(0, 0, 128, 128) // alter the frame depending on the size of the device
self.view.addSubview(imageView)

所以这是我的问题:

  • 显示的图像输出有什么不同吗?

  • 如果您使用 SVG 文件,即使在扩大尺寸后也不必担心看到脏图像,对吧?

  • 哪种方式性能更好或推荐方式更好?

最佳答案

使用 Image assets 为各种设备加载图像性能更高效,速度更快,并受到 apple 本身的鼓励。

关于ios - 我应该使用 xcassets 还是只更改一张图像的大小以在 iOS 的多个设备上开发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32414926/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com