我在我的xcassets中使用了一些pdf图像,并选中了“保留矢量数据”。相同的图像在不同的iOS版本之间呈现方式不同(我使用的是Xcode11.2)。在左侧,图像按iOS 13.2中的预期渲染,在右侧,图像未按iOS 11.4中的预期渲染(与iOS 12.2中相同)。通过删除“保留矢量数据”的复选框,问题不会出现。

创建UIImageViews的代码如下:
self.view.backgroundColor = .white
let imageView = UIImageView(frame: CGRect(x: 10, y: 20, width: self.view.bounds.width - 20, height: self.view.bounds.width - 20))
imageView.image = UIImage(named: "calendar")
imageView.backgroundColor = UIColor.red.withAlphaComponent(0.4)
imageView.contentMode = .center
self.view.addSubview(imageView)Pdf图像大小为27x23像素,通过停止模拟器并打印出图像大小和比例,仍然可以打印正确的值:
(lldb) po ((UIImageView *) 0x7fa1b0c053e0).image.scale
2
(lldb) po ((UIImageView *) 0x7fa1b0c053e0).image.size
(width = 27, height = 23)我是不是遗漏了什么?
发布于 2019-11-07 19:42:18
我知道这听起来可能有点奇怪,但是在UIImageView属性设置中做一个小小的改变就可以解决这个问题:
let imageView = UIImageView(frame: CGRect(x: 10, y: 20, width: self.view.bounds.width - 20, height: self.view.bounds.width - 20))
imageView.contentMode = .center
imageView.image = UIImage(named: "calendar")
imageView.backgroundColor = UIColor.red.withAlphaComponent(0.4)
self.view.addSubview(imageView)首先设置contentMode,然后设置image。
https://stackoverflow.com/questions/58747949
复制相似问题