PDF vector image in Launch Screen, not scaling properly on device

1.1k Views Asked by At

I am using storyboard for my Launch Screen. I have an UIImageView and a UILabel in my Launch Screen. For the UIImageView's image, I am using a .pdf image that is located in Assets.xcassets. The default size of my image is 25x25 px but since it is a vector image it should be able to scale infinitely. The UIImageView has constraints (equal width to superview i.e. device screen, 1:1 aspect ratio, centered in superview). The UIImageView has content mode "Aspect fit". The image appears fine in the storyboard and on simulator. It does not appear as wanted on a real device: the size of the image is correct (fit screen's width) but the image is pixelated. Since it's working fine on the simulator (not pixelated) I have hope it would work the same on device. I know other people had similar issues like the image was not showing at all, and restarting the device or Xcode fixed the issue, but that didn't for me. That's why I think my issue is different since the image is showing up, it's just pixelated. I'd like to precise that my vector image has different colors if that could help.

I already tried basic stuff like: restarting device, restarting Xcode, cleaning build folder, deleting derived data, deleting app from device.

3

There are 3 best solutions below

0
AW5 On BEST ANSWER

Here is a workaround I found: I manually changed the default size of the pdf image to something bigger like 1000x1000 px with an image editor, and then I added the image back in Xcode. The first time the image didn't show up at all, then I turned off the device and restarted it. I build and run again from Xcode and now it works every time.

It works but I'm kinda not completely satisfied with this workaround so if anyone else comes up with anything better, I'm interested!

2
Nishant Singh On

Set image name in code and not in storyboard. Tested on Simulator and Device, works fine when set thru code.

imgVec.image = UIImage.init(named: "yourImageName")

Refer this answer

1
Dimitar Stefanovski On

Checking the Resizing checkbox (Preserve Vector Data) on the Image Set in Assets should scale the PDF image without any issues. enter image description here