Smoothing basic graphics curves

I am trying to create a circular loading bar and want to use Core Graphics instead of masking images to create an effect. However, I do not get the fidelity I was hoping for:enter image description here

No matter what I tried, jaggies seem pretty bad. Anti-aliasing is turned on, and I already tried to turn “flatness” down to .1 on CGContextRef. The image from the simulator (Retina), it looks a little better on the device, but still not so big.

Drawing code in 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, or am I missing something?

+5
source share
1 answer

. CALayer ( ), contentScale Retina. :

percentLayer.contentsScale = [UIScreen mainScreen].scale;

, , , .

+10

All Articles