core graphics CGContextClip - Xcode -


Starting to understand core graphics I'm pulling a path with a fill and a stroke, but I clip it Can not get to. Can anyone tell me what I am doing wrong here?

This code is in the drawRect method of my UIView subclass.

  // A closed path along the edges of the goal, a fill and a stroke CGContextRef reference = UIGraphicsGetCurrentContext (); CGContextSetLineWidth (Reference, 4.0); CGContextSetStrokeColorWithColor (Reference, [UIColor blueColor] .CGColor); CGContextSetFillColorWithColor (Reference, [UIColor redColor] .CGColor); // Fill CGContextMoveToPoint (References, 10, 10); CGContextAddLineToPoint (Reference, 10, 100); CGContextAddArcToPoint (References, 10,140, ​​30,140, ​​20); CGContextAddLineToPoint (Reference, 200, 140); CGContextAddArcToPoint (Reference, 240,140, ​​240,100, 20); CGContextAddLineToPoint (References, 240, 10); CGContextClosePath (reference); CGContextFillPath (reference); // stroke CGContextMoveToPoint (References, 10, 10); CGContextAddLineToPoint (Reference, 10, 100); CGContextAddArcToPoint (References, 10,140, ​​30,140, ​​20); CGContextAddLineToPoint (Reference, 200, 140); CGContextAddArcToPoint (Reference, 240,140, ​​240,100, 20); CGContextAddLineToPoint (References, 240, 10); CGContextClosePath (reference); CGContextStrokePath (reference); CGContextBeginPath (reference); // clip ?? CGContextMoveToPoint (References, 10, 10); CGContextAddLineToPoint (Reference, 10, 100); CGContextAddArcToPoint (References, 10,140, ​​30,140, ​​20); CGContextAddLineToPoint (Reference, 200, 140); CGContextAddArcToPoint (Reference, 240,140, ​​240,100, 20); CGContextAddLineToPoint (References, 240, 10); CGContextClosePath (reference); CGContextClip (reference);    

before CGContextClip before CGContextStrokePath And CGContextClosePath after. That’s enough. No need to write additional code, try the following as such.

  CGContextClosePath (reference); CGContextClip (reference); CGContextStrokePath (reference);   

I think this will be helpful to you.

Comments