绘制圆形渐变

2024-04-02

我想绘制一个圆形渐变,如下图所示。我可以轻松管理径向渐变,但我不知道如何做圆形渐变。 我正在考虑在一条线上绘制渐变,然后将其转换为圆形。这可能吗?

这就是我绘制径向渐变的方法:

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);

多谢!


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

绘制圆形渐变 的相关文章

随机推荐