Is loading an image or using CGGradient more efficient?

I am experimenting with some things for a new interface in one of my applications. I am wondering what is the most efficient way to add user interface elements like gradient background (taking into account both the size of the application and the speed / memory consumption).

Wouldn't it be better to create elements in something like Inkscape or Illustrator and then load them through UIImage> UIIMageView? Or would it be better to use CGGradient or CAGradientLayer ?

In addition, I wonder about these things quite often, and I wonder if anyone can explain how I can test these things for myself (speed, memory consumption, overall performance).

+4
source share
1 answer

CAGradientLayers are pretty good. I almost always prefer drawing gradients using CGGradient, or using CAGradientLayer, using images, especially because you don’t need to turn on the retina / non-retina grid, iPhone / iPad combinations and change colors become a matter of setting one line of code rather than regenerating the whole series images in your image processing software.

If you are doing another drawing in drawRect, draw with CGGradient. If you only need a background, use the CAGradientLayer.

You can analyze performance using tools (product -> profile in Xcode)

  • main animation tool will give you frames per second if there is scrolling / animation
  • a time profiling tool will show you which features take up your time.
  • various memory tools will show you memory consumption
+3
source

All Articles