Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing part of CGPath

How to remove some part of my Path? I have a path drawn in my screen, and now lets say I would like to remove 1/3:

Like that

I tried to do it in this way(path is my original path, cPath is copy which will be clipped):

let sizePath = CGPathGetBoundingBox(path).size
UIGraphicsBeginImageContext(sizePath)
let context = UIGraphicsGetCurrentContext()
let cPath = CGPathCreateMutableCopy(path)
CGContextAddPath(context, cPath)
CGContextDrawPath(context, .Stroke)
let rect = CGRectMake(currentPosition.x, 0, sizePath.width, sizePath.height)
CGContextClipToRect(context, rect)
//How to Recive here this Clipped Path from context???

UIGraphicsEndImageContext()

But I don't know how to receive this path from my context...

like image 373
EvIld95 Avatar asked Dec 03 '25 09:12

EvIld95


1 Answers

You need to CGContextClipToRect before you CGContextDrawPath. The clip region only affects subsequent drawing.

like image 162
rob mayoff Avatar answered Dec 05 '25 01:12

rob mayoff