开发者

CGContextDrawPath Stroke disappears if Fill is added

trying to draw circle divided to dynamically provided number of sectors. In the end my circle should look like pie.

I've created class Circle which contains number of Pies inside. Circle has method - (void)draw which calles [pie draw]; in for (Pie *pie in self.pies) loop.

Implementation of pie looks like this:

- (void)draw {  

  CGContextRef context = UIGraphicsGetCurrentContext();

  float startAngleRads = degreesToRadians(_startAngle);
  float endAngleRads = degreesToRadians(_endAngle);


  CGContextBeginPath(context);
  CGContextSetLineWidth(context, 1.0f);
  CGContextSetLineCap(context, kCGLineCapRound);
  CGContextSetLineJoin(context, kCGLineJoinRound);

  CGColorRef strokeColor = [_strokeColor CGColor];
  CGContextSetStrokeColorWithColor(context, strokeColor);

  CGColorRef fillColor = [_bgCol开发者_StackOverflow社区or CGColor];
  CGContextSetFillColorWithColor(context, fillColor);


  CGContextMoveToPoint(context, _x, _y);
  CGContextAddArc(context, _x, _y, _r, startAngleRads, endAngleRads, YES);
  CGContextDrawPath(context, kCGPathStroke);

  CGContextFlush(context);
}

This draws nice circle with sectors but without any filling of course. When I change last lines to CGContextDrawPath(context, kCGPathStrokeFill); my stroke lines disappears and only last line (last sector) stays at the screen, other parts of circle are filled with bgcolor and no stroke is visible anymore.

The question is: how can I draw completly separated "sectors" (every sector should look like triangle with Arc and Stroke and Fill). I need this because I want to toggle visibility of that sectors but at the moment I cant even figure out how to draw them correctly.

If this is important, all drawing happens on the layer with self.opaque = NO;.


Ok, found my error: had to set NO in CGContextAddArc call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜