7
我想在我的iOS應用程序中創建下面的圈子。我知道如何製作圈子,但我不完全確定如何獲得弧形點。它必須在代碼中而不是圖像。以下是我目前擁有的代碼。iOS繪圖圈
- (void)drawRect:(CGRect)rect
{
CGPoint point;
point.x = self.bounds.origin.x + self.bounds.size.width/2;
point.y = self.bounds.origin.y + self.bounds.size.height/2;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGRect circle = CGRectMake(point.x/2,point.y-point.x/2,point.x,point.x);
CGContextAddEllipseInRect(context, circle);
CGContextStrokePath(context);
for (int i = 0; i<8; i++) {
CGRect circleMini = CGRectMake(??????,??????,point.x/4,point.x/4);
CGContextAddEllipseInRect(context, circleMini);
CGContextStrokePath(context);
}
}
更新到ANSWER
float cita = 0;
for (int i = 0; i<8; i++) {
CGPoint pointCir = CGPointMake(point.x/2 + radius * cos(cita) , (point.y-point.x/2) + radius * sin(cita));
CGRect circleMini = CGRectMake(pointCir.x,pointCir.y,radius/4,radius/4);
CGContextAddEllipseInRect(context, circleMini);
CGContextStrokePath(context);
cita += M_PI/4.0;
}
它不工作。我只是得到了大圈子。你能看到我如何在上面實現它。我做錯了嗎? – BDGapps 2013-03-05 23:16:26
你應該使用cita + = M_PI/4.0,而不是cita = M_PI/4,根據你的實現,不是圓心(point.x/2,point.y-point.x/2)? – ikaver 2013-03-05 23:27:58
我更新了上面的代碼,但同樣的問題 – BDGapps 2013-03-05 23:33:28