UIColor SetFill doesn't work

前端 未结 2 626
北荒
北荒 2021-01-25 16:11

In this code

for (int i=0;i<3;i++) {
    CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*(i+1), self.yShift+self.rectLen*         


        
相关标签:
2条回答
  • 2021-01-25 16:28

    Not only do you need to call the appropriate CG* methods to set the fill like David suggested, you need to actually perform the fill using the following after you set the fill and stroke properties:

    CGContextSetFillColorWithColor(context, [UIColor cyanColor].CGColor);
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor.CGColor);
    CGContextFillPath(context);
    CGContextStrokePath(context);
    
    0 讨论(0)
  • 2021-01-25 16:44

    setFill isn't for Core Graphics drawing but for drawing like [myUIBezierPath fill];

    Instead set the fill color and stroke color using:

    CGContextSetFillColorWithColor(context, [[UIColor cyanColor] CGColor]);
    CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
    

    Also, the following line:

    CGContextDrawPath(context, kCGPathStroke);
    

    Will only stroke the path, since the drawing mode is set to kCGPathStoke. To fill it as well you should replace it with

    CGContextDrawPath(context, kCGPathFillStroke);
    

    If your path has holes in it or crosses itself you should use even-odd fill and stroke

    CGContextDrawPath(context, kCGPathEOFillStroke);
    
    0 讨论(0)
提交回复
热议问题