1
我想要像这样创建一个圆形渐变进度条:iOS中使用CoreGraphics中
我试图与核芯显卡这样使它:
float radius = CGRectGetWidth(rect)/2.0f - self.circleBorderWidth/2.0f;
float angleOffset = 0;
UIBezierPath *aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect))
radius:radius
startAngle:-angleOffset
endAngle:(mCircleSegs + 1)/(float)kCircleSegs*M_PI*2 - angleOffset
clockwise:YES];
CGPathRef shape = CGPathCreateCopyByStrokingPath(aPath.CGPath, NULL, 3, kCGLineCapSquare, kCGLineJoinMiter, 1.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx, shape);
CGContextClip(ctx);
AngleGradientLayer *angle = [[AngleGradientLayer alloc] init];
angle.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor,
(id)[UIColor colorWithRed:1 green:1 blue:1 alpha:1].CGColor,
nil];
CGContextClipToRect(ctx, self.bounds);
[angle drawInContext:ctx];
[angle release];
但我认为我在这里错了。它看起来不像这个例子。 CoreGraphics能够绘制这样的东西吗?怎么样?
问题不是圆的2个部分。问题在于渐变的绘制。我真的不知道如何用核心图形绘制这样的东西。 – Hans 2013-02-18 00:13:57
回答编辑,添加了我得到的截图 – Vinzzz 2013-02-18 07:35:59
是的!但正如你在上面的图片中看到的那样,当进度条是20%,60%,80%时......第一部分的结尾总是最白的。所以背景层不是解决方案。事实上,我想我们需要一个适应进度本身的背景...... – Hans 2013-02-18 11:08:08