I thought the new Preserves Vector Data checkmark in the Xcode 9 asset catalog would finally give us resizing of vector PDF images, but apparently not. Here\'s my test image
In my case (Xcode 9.4.1), with imageView
created in Interface Builder - I noticed that when I initially arrive on the screen, the image is blurry. If I then change device orientation, the image becomes crisp. I tried calling different methods manually in viewDidLoad()
and here is what I found so far:
This worked:
let image = imageView.image
imageView.image = nil
imageView.image = image
None of these worked:
imageView.layoutSubviews()
imageView.layoutMarginsDidChange()
imageView.setNeedsLayout()
imageView.setNeedsDisplay()
imageView.reloadInputViews()
imageView.updateConstraints()
imageView.contentMode = .center ; imageView.contentMode = .scaleToFill
You should of course extend or subclass UIImageView
if you'll be calling it often, like this for example
class UIImageViewWithPreserveVectorDataFix: UIImageView {
override func awakeFromNib() {
super.awakeFromNib()
let image = self.image
self.image = nil
self.image = image
}
}
(and then of course set UIImageViewWithPreserveVectorDataFix
as the class in Interface Builder)