Search code examples
iphoneobjective-cuiimagegradientradial-gradients

How to render a radial gradient onto a new UIImage on an iphone


Just wondering how to render a radial gradient (point > circle) onto a new UIImage (iphone). I saw the following:

http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html

And it made me think i need to use CGShadingRef or CGGradientRef, and use UIImage's 'imageWithCGImage' constructor to go from the CG* to a UIImage... but i can't figure out how.

Any suggestions greatly appreciated!


Solution

  • You should read about Graphics Contexts in the same document as the section you linked. All drawing happens in a graphics context. If you want to create an image that has a radial gradient, or a linear gradient, or anything else, you'll need to: