2

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.

AW5
  • 406
  • 3
  • 12
  • What's the minimum iOS version that you are targeting? – Eugene Dudnyk Aug 15 '20 at 00:28
  • iOS 12.0, also I'm on Xcode 11.6 and the device with the issue is an iPhone 11 with iOS 13.6 if that helps @EugeneDudnyk – AW5 Aug 15 '20 at 00:29
  • Did you set "preserve vector data" and "always template" to your pdf asset? – Eugene Dudnyk Aug 15 '20 at 00:55
  • I did set "preserve vector data" but not "always template" because that would remove the colors from my images. I can't set the color with the tint color because I have more than one color in my image. But it's working fine on the simulator. – AW5 Aug 15 '20 at 01:03
  • Doesn’t it work on both iOS 12 and 13? – Eugene Dudnyk Aug 15 '20 at 01:15
  • I assume so but I don't know because I only have an iOS 13.6 device. – AW5 Aug 15 '20 at 01:21
  • These are things I would try: 1) Try to retest after setting min iOS version to 13.0 2) Download Xcode 12 beta and try to use svg instead of pdf in the asset catalog. – Eugene Dudnyk Aug 15 '20 at 01:38
  • Thanks for your help but I want to keep iOS 12 as minimum target and don't want to install beta software as it might be unstable. I actually just found a workaround as you can see. – AW5 Aug 15 '20 at 02:04

3 Answers3

0

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!

AW5
  • 406
  • 3
  • 12
0

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

  • I was using that for all vector images, but at that time, that still didn't help for the launch screen image, which I believe is a different case than any random vector image in the app. – AW5 Feb 23 '23 at 00:37
-1

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