Skip to content

Instantly share code, notes, and snippets.

@timgcarlson
Last active June 10, 2021 22:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timgcarlson/5ae77b5f9c57c1cf96f7aac32ee6a03d to your computer and use it in GitHub Desktop.
Save timgcarlson/5ae77b5f9c57c1cf96f7aac32ee6a03d to your computer and use it in GitHub Desktop.
Using the non-zero winding rule to cutout the path of a shape (uses bezierPathByReversingPath)
UIGraphicsBeginImageContextWithOptions(CGSize(width: 200, height: 200), false, 0.0)
let context = UIGraphicsGetCurrentContext()
let rectPath = UIBezierPath(roundedRect: CGRectMake(0, 0, 200, 200), cornerRadius: 10)
var cutoutPath = UIBezierPath(roundedRect: CGRectMake(30, 30, 140, 140), cornerRadius: 10)
rectPath.appendPath(cutoutPath.bezierPathByReversingPath())
UIColor.orangeColor().set()
outerForegroundPath.fill()
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment