Andrew Andrew - 1 month ago 6
iOS Question

How do I add a radial gradient to a UIView?

I have a

UIView
which I want to have a radial gradient, and I'm wondering how to go about doing this?

Answer

To do this you need to drop down to Core Graphics and use CGContextDrawRadialGradient.

Similar Stack Overflow Questions

How can I draw a sector with radial gradient (iphone)

How to draw a gradient line (fading in/out) with Core Graphics/iPhone?

Other Resources

There's a tutorial showing how to draw icons with gradients on iOS here:

http://redartisan.com/2011/05/13/porting-iconapp-core-graphics

He's put the code on Github, complete with a UIView subclass that shows the (rather longwinded) way of making gradients using Core Graphics:

https://github.com/crafterm/IconApp/blob/master/IconApp/IconView.m

Comments