Drawing with Core Graphics looks chunky on Retina

2020-03-24 11:06发布

I have a UIView that draws a circle from inside drawRect:rect. After reading the Apple dev info on the Retina display, it seemed like using Core Graphics meant that the drawings would automatically take advantage of the higher res. This simple circle, however, looks pretty chunky as compared to a similar circle in a badge icon. Obviously I'm comparing it to something that has gloss and shadow but I think it's pretty obvious that mine is not being drawn as well. I tried taking screenshots of apple's icon badge and my circle and they look about the same on my mac - the difference is obvious when looking at each on the phone, though. Is there something simple I'm missing here?

This is the drawing code that I'm using in drawRect:rect

UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect:
                       CGRectMake(0, 0, 22, 22)];

[[UIColor whiteColor] setStroke];
[[UIColor redColor] setFill];

CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(aRef, 10, 10);
aPath.lineWidth = 3;
[aPath fill];
[aPath stroke];

Thanks for any help, Rob

1条回答
对你真心纯属浪费
2楼-- · 2020-03-24 11:36

Oops, it needed antialiasing first:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, YES);

I added this before drawing, then set it to NO and drew another circle immediately afterward. The two circles, side by side, show that this was the problem.

查看更多
登录 后发表回答