1

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

Community
  • 1
  • 1
Horatiu Paraschiv
  • 1,750
  • 2
  • 15
  • 37

1 Answers1

2

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.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • @Horatiu: all I'd add is that one of the main purposes of CALayer is to cache graphics on the GPU so that they can be composited and have their movements animated without being redrawn. So you shouldn't worry particularly much about implementing a slow algorithm for drawing your gradient if taking Noah's advice. – Tommy Sep 08 '11 at 21:11