绘制圆梯度

我想绘制一个圆形渐变,如下面的示例图片。 我可以很容易地pipe理径向渐变,但我不知道如何做一个循环。 我正在考虑在一条线上绘制渐变,然后将其转化为一个圆。 这可能吗?

在这里输入图像说明

这是我如何绘制径向渐变:

CGFloat a = MIN(self.frame.size.width, self.frame.size.height) - _lineWidth; //Get current context CGContextRef mainContext = UIGraphicsGetCurrentContext(); CGRect newRect = rect; newRect.origin.x = ((self.frame.size.width - a)/2.0f); newRect.origin.y = ((self.frame.size.height - a)/2.0f); newRect.size.width = a; newRect.size.height = a; // Fill circle const CGFloat *_components = CGColorGetComponents(_fillColor.CGColor); CGFloat red = _components[0]; CGFloat green = _components[1]; CGFloat blue = _components[2]; CGFloat alpha = _components[3]; CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB(); CGFloat redBallColors[] = { red,green,blue,0.5, red,green,blue,alpha, }; CGFloat glossLocations[] = {0.0, 1.0}; CGGradientRef ballGradient = CGGradientCreateWithColorComponents(baseSpace, redBallColors, glossLocations, 2); CGPoint startPoint = self.center; CGPoint endPoint = self.center; CGContextDrawRadialGradient(mainContext, ballGradient, startPoint, 0, endPoint, a/2, 0); 

非常感谢!