我必须仅在弧线中用渐变颜色填充弧线你能不能提供解决方案enter image description here
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIBezierPath *arc = [UIBezierPath bezierPathWithArcCenter:barCenter radius:barRadius startAngle:fmodf(MIN_ANGLE+M_PI, 2*M_PI) endAngle:fmodf(MAX_ANGLE+M_PI, 2*M_PI) clockwise:YES];
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, kArcThickness);
CGContextSetGrayStrokeColor(ctx, 0.6, 1.0);
CGContextAddPath(ctx, arc.CGPath);
CGContextStrokePath(ctx);
// knob to move the slider
CGContextSetLineWidth(ctx, 2.0);
CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor);
CGContextAddArc(ctx, knobCenter.x, knobCenter.y, knobRadius, 0, 2*M_PI, 1);
CGContextDrawPath(ctx, kCGPathFill);
答案 0 :(得分:0)
尝试使用以下代码..
//list of components
CGFloat components[8] = {
0.0, 0.0, 1.0, 1.0, // Start color - Blue
1.0, 0.0, 1.0, 1.0 }; // End color - Violet
CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, components, NULL, 2);
CGColorSpaceRelease(baseSpace), baseSpace = NULL;
//Gradient direction
CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
//Draw the gradient
CGContextDrawLinearGradient(ctx, gradient, startPoint, endPoint, 0);
CGGradientRelease(gradient), gradient = NULL;
CGContextRestoreGState(ctx);