I am experimenting with a few things for a new UI in one of my apps. I’m wondering, what is the most efficient way to add UI elements like a gradient background (keeping in mind both the size of the app as well as speed/memory consumption).
Would I be better off just creating the elements in something like Inkscape or Illustrator, and then loading them in via UIImage>UIIMageView? Or would it be best to use CGGradient or CAGradientLayer?
Also, I wonder about these kinds of things quite often and I’m wondering if someone could explain how I could test these kinds of things for myself (speed, memory consumption, overall performance).
CAGradientLayers are pretty good.I’d nearly always favour drawing gradients using CGGradient or using a CAGradientLayer over using images, particularly since you then don’t need to include retina/non-retina, iPhone/iPad combinations, and changing the colours becomes a matter of tweaking one line of code rather than regenerating a whole series of images in your imaging software.
If you’re doing other drawing in drawRect as well, draw with a CGGradient. If you just want a background, use CAGradientLayer.
You can analyse the performance using Instruments (product –> profile in XCode)