Last active
June 10, 2021 22:04
-
-
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)
This file contains 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
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