在calayer对象上的自定义绘制的东西看起来相当pixeled

时间:2012-10-21 17:32:46

标签: 2d calayer pixel

我的drawInContext方法看起来像这样:

- (void)drawInContext:(CGContextRef)context {
CGRect circleRect = CGRectInset(self.bounds, 1, 1);

UIColor * __autoreleasing borderColor = [UIColor whiteColor];
UIColor * __autoreleasing backgroundColor = [UIColor colorWithWhite:0 alpha: 0.75];

CGContextSetFillColorWithColor(context, backgroundColor.CGColor );
CGContextSetStrokeColorWithColor(context, borderColor.CGColor );
CGContextSetLineWidth(context, 2.0f);

CGContextFillEllipseInRect(context, circleRect);
CGContextStrokeEllipseInRect(context, circleRect);

CGFloat radius = MIN(CGRectGetMidX(circleRect), CGRectGetMidY(circleRect));
CGPoint center = CGPointMake(radius, CGRectGetMidY(circleRect));
CGFloat startAngle = -M_PI / 2;
CGFloat endAngle = self.progress * 2 * M_PI + startAngle;
CGContextSetFillColorWithColor(context, borderColor.CGColor );
CGContextMoveToPoint(context, center.x, center.y);
CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0);
CGContextClosePath(context);
CGContextFillPath(context);

[super drawInContext:context];
}

但是在我的iPhone Retina显示屏上,截​​图显示它看起来很像。猫怎么修这个?

enter image description here

1 个答案:

答案 0 :(得分:11)

好的,我找到了解决方案。要绘制精美缩放的图像,需要执行以下操作:

pie_layer.contentsScale = [UIScreen mainScreen].scale;

另见帖子:CGContext text drawing doesn't scale up on iPhone 4