Drawing in iOS - Part 12: Challenge: Customize | Ray Wenderlich Videos

Complete your custom button in this hands-on challenge.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4659-drawing-in-ios/lessons/12

Caroline, thank you so much for this set of tutorials. I’ve found them (as well as your other tutorials) crystal clear and super helpful.

One question for you – for buttons (or other small views) like this, would it be more efficient to use a preset image (e.g. in PNG format) or to use core-graphics to draw it at run time?

Thank you again!!

1 Like

@variadic - thanks :blush:

If it’s just images on the screen loaded once, then the difference would be negligible. If it’s multiple images vs core graphics drawing in a scrolling table, then I haven’t tested the efficiency. If the image were different every cell, then I’m pretty sure that UIImageViews would be more efficient.

The main difference is in image clarity and efficiency of creating the images. You’d have to create 2x and 3x resolution images and make sure they are drawn to exactly the right size so as not to resize unsharply. (Or you could use pdf vector images which should scale).

For example if you’re using the same button image in two places with different view sizes, then if you scale the png, it’s not going to be as sharp as if you don’t.

With core graphics, you’re guaranteed that the size you draw is the exact right size for that view.

But if you prefer using pngs (or pdf if you want to scale) there’s absolutely nothing wrong with that! Most times I would use images myself rather than drawing them at runtime. However, with core graphics, you do get the option of responding to what’s happening in the app.

@caroline Thank you for your answer! It’s very helpful. :smile: