Xcode 6 allows VECTOR image assets… how to use them?

后端 未结 7 1501
青春惊慌失措
青春惊慌失措 2020-11-28 02:00

I was fiddling with Xcode 6 vs images assets when I noticed something very interesting: we now can specify vector images in them (go see in the Utilities pa

7条回答
  •  余生分开走
    2020-11-28 02:28

    If you're looking for an answer to the question: "How can I use vector graphics in my iOS app and always scale them with beautiful perfection?", then I can highly recommend UIImage+PDF from https://github.com/mindbrix/UIImage-PDF

    I find this works absolutely brilliantly. Instead of having all images in PNG format of three different resolutions, I now have a tiny little PDF file for each image. I can display these as follows:

    // Objective C:
    self.icon.image = [UIImage imageWithPDFNamed:@"icon.pdf" fitSize:self.icon.frame.size];
    
    // Swift:
    icon.setImage(UIImage(PDFNamed: "icon.pdf", fitSize: icon.frame.size))
    

    In addition to fitSize:, there is also atWidth:, atHeight and atSize:.

    I'm using UIImage+PDF for all images that can be vectorized, and only use PNGs still for photo images.

    I'm also running my PDF files through something like http://smallpdf.com/compress-pdf, to ensure the smallest file sizes for them.

    Erik

提交回复
热议问题