【iOS】正多角形を描く - UIBezierPathバージョン2
こないだのだとなんか傾いてるので。
- (void)drawRegularPolygon:(NSUInteger)p radius:(CGFloat)radius center:(CGPoint)center { UIBezierPath *aPath = [UIBezierPath bezierPath]; aPath.lineWidth = 1; for (NSInteger i = 0; i < p; i++) { double rad = M_PI * i * 2 / p + M_PI_2; CGPoint drawPoint = CGPointMake(center.x + radius * cos(rad), center.y - radius * sin(rad)); if (i == 0) [aPath moveToPoint:drawPoint]; else [aPath addLineToPoint:drawPoint]; } [aPath closePath]; [[UIColor redColor] setStroke]; [aPath stroke]; }