Drawing with Core Graphics looks chunky on Retina display

只谈情不闲聊 提交于 2019-12-01 04:38:54

问题


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:


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.



来源:https://stackoverflow.com/questions/5291510/drawing-with-core-graphics-looks-chunky-on-retina-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!