我试图通过使用CAShapeLayer并在其上设置圆形路径来绘制一个描边圆.但是,这种方法在渲染到屏幕时的效果始终低于使用borderRadius或直接在CGContextRef中绘制路径.
以下是所有三种方法的结果: 
请注意,第三个渲染效果不佳,尤其是在顶部和底部的笔划内.
我已将该contentsScale属性设置为[UIScreen mainScreen].scale.
这是我对这三个圆圈的绘图代码.使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(), 1);
[[UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.bounds, 4, 4)] stroke];
}
@end
@interface BCShapeView : UIView
@end
@implementation BCShapeView
+ (Class)layerClass
{
return [CAShapeLayer class];
} …Run Code Online (Sandbox Code Playgroud) 这里不是图形程序员,所以我试图绊倒这个.我正在尝试绘制9个实心圆圈,每个圆圈都有不同的颜色,每个圆圈都有一个白色边框.UIView的框架是CGRectMake(0,0,60,60).见附图.
问题是我在每边的边界上都有"扁平斑点".以下是我的代码(来自UIView子类):
- (void)drawRect:(CGRect)rect
{
CGRect borderRect = CGRectMake(0.0, 0.0, 60.0, 60.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBFillColor(context, colorRed, colorGreen, colorBlue, 1.0);
CGContextSetLineWidth(context, 2.0);
CGContextFillEllipseInRect (context, borderRect);
CGContextStrokeEllipseInRect(context, borderRect);
CGContextFillPath(context);
}
Run Code Online (Sandbox Code Playgroud)
如果我在drawRect中更改为CGRectMake(0,0,56,56),我只会在顶部和左侧看到平点,并且底部和右侧看起来很好.
任何人都可以建议我如何解决这个问题?在我看来,UIView正在修剪边界,但对此并不了解,我真的不知道如何修复它.
在此之前,感谢任何图形专家的建议.
