我不是一名图形编程人员,所以我正在尝试摸索。我想画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);
}
如果我在drawRect中更改为CGRectMake(0,0,56,56),则只在顶部和左侧出现平面区域,底部和右侧看起来正常。有人能建议我如何解决吗?我觉得边框被UIView裁剪了,但不知道怎么修复它。
感谢所有图形专家提供的建议。
CGContextFillPath(context);
是不必要的。 - Daniel