0
所以,我有这个代码,它围绕它画一个圆圈。CGContextRef插入?
- (void)drawRect:(CGRect)rect
{
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 40.0);
CGContextSetRGBFillColor(contextRef, 0.0, 0.0, 0.0, 1.0);
CGContextSetRGBStrokeColor(contextRef, 132.0/255.0, 128.0/255.0, 128.0/255.0, 1.0);
CGContextFillEllipseInRect(contextRef, rect);
CGContextStrokeEllipseInRect(contextRef, rect);
}
问题是这条线的宽度的一半超出了矩形的范围。 所以,我想要做的是创建一个相对于线宽的插图,以弥补这一点。 或者,也许有一种方法,告诉我的线保持在圈内?
现在很容易。我想我应该多做一些阅读。 所以,实际上,代码将是 float linewidth = 40; ... CGContextSetLineWidth(contextRef,linewidth); ... rect = CGRectInset(rect,linewidth/2,linewidth/2); CGContextFillEllipseInRect(contextRef,rect); – Sjakelien