Search code examples
iphoneiosuikitcore-graphicsquartz-2d

How do I draw an angle gradient using CALayer or CoreGraphics functions?


Possible Duplicate:
CGContextDrawAngleGradient?

HI I want to draw a gradient like the one below in a UIView or CALayer using Quartz2D or CoreGraphics methods.

Does anyone know how can I achieve that?

Any snippet would be great.

Thank you!

This Gradient


Solution

  • Unfortunately, Core Graphics and Quartz only support axial (linear) and radial (circular) gradients. For an angle gradient you’ll either have to draw it manually (perhaps by drawing triangles in a circle at a resolution fine enough for the color shifts to be unnoticeable) or have a precomposed angle-gradient image that you resize and clip to your drawing needs.