Skip to content

Instantly share code, notes, and snippets.

@algal
Created October 23, 2015 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save algal/5648b51e67061a189f76 to your computer and use it in GitHub Desktop.
Save algal/5648b51e67061a189f76 to your computer and use it in GitHub Desktop.
Get the outline of a path
/// Given `path`, drawn with `width`, returns a new path outlining its edges
func pathOutliningPath(path:UIBezierPath, withWidth width:CGFloat, inSize size:CGSize) -> UIBezierPath
{
UIGraphicsBeginImageContextWithOptions(size, false, 0)
let ctx = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(ctx, width)
CGContextAddPath(ctx, path.CGPath)
CGContextReplacePathWithStrokedPath(ctx)
let extractedCGPath = CGContextCopyPath(ctx)
UIGraphicsEndImageContext()
let extractedPath = UIBezierPath(CGPath: extractedCGPath!)
return extractedPath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment