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