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

时间:2015-09-05 15:47:40

标签: ios uiimage uicollectionview xcasset

我希望在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文件,即使在扩大尺寸后也不用担心看到脏图像,对吗?

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

1 个答案:

答案 0 :(得分:1)

使用图像资源为各种设备加载图像更具性能效率和速度,并受到苹果公司的鼓励。

相关问题