Created
October 23, 2015 06:00
-
-
Save algal/5648b51e67061a189f76 to your computer and use it in GitHub Desktop.
Get the outline of a path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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