Tag: cashapelayer

如何用CAShapeLayer和UIBezierPath绘制一个平滑的圆?

我试图通过使用CAShapeLayer并在其上设置循环path来绘制一个描边圈。 但是,这种方法在渲染到屏幕上的准确性比使用borderRadius时要less得多,或者直接在CGContextRef中绘制path。 以下是所有三种方法的结果: 请注意,第三个渲染效果不好,特别是在顶部和底部的中风。 我已经将contentsScale属性设置为[UIScreen mainScreen].scale 。 这是我的这三个圈子的绘图代码。 缺less什么使CAShapeLayer平滑绘制? @interface BCViewController () @end @interface BCDrawingView : UIView @end @implementation BCDrawingView – (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { self.backgroundColor = nil; self.opaque = YES; } return self; } – (void)drawRect:(CGRect)rect { [super drawRect:rect]; [[UIColor whiteColor] setFill]; CGContextFillRect(UIGraphicsGetCurrentContext(), rect); CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), NULL); [[UIColor redColor] setStroke]; CGContextSetLineWidth(UIGraphicsGetCurrentContext(), […]