Xcode: Vector images from PDF bad quality

后端 未结 3 2091
再見小時候
再見小時候 2021-02-18 14:17

for my iOS Swift project I use vectorized pdf files from which Xcode renders the @1x, @2x, @3x images.

When I compare the quality of the images generated from P

相关标签:
3条回答
  • 2021-02-18 14:44

    I would set the Preserve Vector Data flag on the asset here:

    This will make it render as a pdf and scale properly.

    0 讨论(0)
  • 2021-02-18 14:51

    The PDF should be saved at 1x resolution, Xcode will take that file and rasterize it generating the @1x, @2x and @3x bitmap versions for you.

    In your case 3 PNGs with the following dimensions will be generated from your PDF:

    • icon.png (54x40px)
    • icon@2x.png (108x80px)
    • icon@3x.png (162x120px)

    From the screenshot you've posted it doesn't appear that the UIImageView in the cell has a size that matches the icon, therefore you get the blur. It's important to understand that the vector image won't be used as such, but will be always rasterized.

    Try to save the PDF with the resolution of the UIImageView (100x82px as per your comment) and check again the result.

    0 讨论(0)
  • 2021-02-18 15:02

    Steps for set a vector image in UIImage :

    1 - Convert your svg image to pdf format

    2 - Add pdf image to your assets

    3 - Select your image and from attribute inspector tab (1.check Preserve Vector Data AND 2.set Scales type in Single Scale)

    4 (very important) - Set image name in code and not in storyboard

    imgVec.image = UIImage.init(named: "yourImageName")
    
    0 讨论(0)
提交回复
热议问题