UIBezierPath绘制不同笔画的圆

基本上我需要有一个不同颜色的笔画,大小相等。 例如,1/2是蓝色,1/2是红色。 图片(对不起,这么糟糕的形象):

例

我怎样才能画出这样的东西?

有很多方法可以做到,但其中一个就是绘制两条贝塞尔path,每条path一条:

 - (void)drawRect:(CGRect)rect { UIBezierPath *blueHalf = [UIBezierPath bezierPath]; [blueHalf addArcWithCenter:CGPointMake(100, 100) radius:90.0 startAngle:-M_PI_2 endAngle:M_PI_2 clockwise:YES]; [blueHalf setLineWidth:4.0]; [[UIColor blueColor] setStroke]; [blueHalf stroke]; UIBezierPath *redHalf = [UIBezierPath bezierPath]; [redHalf addArcWithCenter:CGPointMake(100, 100) radius:90.0 startAngle:M_PI_2 endAngle:-M_PI_2 clockwise:YES]; [redHalf setLineWidth:4.0]; [[UIColor redColor] setStroke]; [redHalf stroke]; } 

或者,如果你想在Core Graphics中做到这一点:

 - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 4); CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]); CGContextAddArc(context, 100, 100, 90, -M_PI_2, M_PI_2, FALSE); CGContextStrokePath(context); CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]); CGContextAddArc(context, 100, 100, 90, M_PI_2, -M_PI_2, FALSE); CGContextStrokePath(context); }