Search code examples
iphoneobjective-ciosperformancequartz-graphics

What's faster: Creating a gradient programmatically using Quartz2D or just importing an image?


Let's assume the file space on the iphone isn't an issue, what would perform better? Would there be any noticeable speed/smoothness difference between the two?


Solution

  • Whilst not specifically targeting gradients (rather patterns) this tutorial by Ray Wenderlich does have some basic information at the bottom with regards images vs. Core Graphics drawing.

    TL;DR Core Graphics is seemingly quite a bit faster when used in this context.

    For what it's worth, I do as much drawing as possible in my app using Core Graphics including such things as radial gradients and textured UILabel's. As a developer with limited design skills I find I often get far better results drawing this way than fumbling about using something like Photoshop.

    Another advantage with using Core Graphics is that you can change things on the fly with ease, such as animating a gradient, which would be incredibly expensive were you to do it solely with images.