I'm trying to create a circular loading bar and want to use Core Graphics instead of masking images to create the effect. However, I'm not getting the fidelity that I was hoping for:
No matter what have I've tried, the jaggies seem pretty bad. Antialiasing is on and I've already tried turning the "flatness" down to .1 on the CGContextRef
. The image is from the (Retina) simulator, it looks slightly better on a device but still isn't that great.
Drawing code, within a subclass of CALayer:
-(void)drawInContext:(CGContextRef)ctx {
CGPoint center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
CGFloat delta = toRadians(360 * percent);
CGFloat innerRadius = 69.5;
CGFloat outerRadius = innerRadius + 12;
CGContextSetFillColorWithColor(ctx, [UIColor colorWithRed:99/256.0 green:183/256.0 blue:70/256.0 alpha:.5].CGColor);
CGContextSetStrokeColorWithColor(ctx, [UIColor colorWithRed:99/256.0 green:183/256.0 blue:70/256.0 alpha:10.0].CGColor);
CGContextSetLineWidth(ctx, 1);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRelativeArc(path, NULL, center.x, center.y, innerRadius, -(M_PI / 2), delta);
CGPathAddRelativeArc(path, NULL, center.x, center.y, outerRadius, delta - (M_PI / 2), -delta);
CGPathAddLineToPoint(path, NULL, center.x, center.y-innerRadius);
CGContextAddPath(ctx, path);
CGContextFillPath(ctx);
CGContextAddPath(ctx, path);
CGContextStrokePath(ctx);
}
Is this the best Core Graphics can do or am I missing something?
ctx
in some other method or is the framework passing it to you? What is the output ofNSLog("%@", [[[UIApplication sharedApplication] keyWindow] recursiveDescription])
? – rob mayoffrecursiveDescription
.KDGoalBar
is the UIControl subclass this is being placed in andKDGoalBarPercentLayer
is where the actual drawing is being done. – Kevin