平滑核心图形曲线

时间:2012-01-10 21:05:10

标签: ios core-graphics calayer

我正在尝试创建一个圆形加载栏,并希望使用Core Graphics而不是屏蔽图像来创建效果。但是,我没有得到我所希望的忠诚度:enter image description here

无论我尝试过什么,锯齿似乎都很糟糕。抗锯齿已经开启,我已经尝试将“平坦度”降低到CGContextRef上的.1。该图像来自(Retina)模拟器,它在设备上看起来略微但仍然不是很好。

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

这是最好的Core Graphics可以做的还是我错过了什么?

1 个答案:

答案 0 :(得分:11)

找出我的具体问题。由于我创建了CALayer(要添加为子图层),contentScale并未自动设置为Retina显示。这解决了它:

percentLayer.contentsScale = [UIScreen mainScreen].scale;

感谢Rob,让我朝着正确的方向前进。

相关问题