Created
May 12, 2017 12:53
-
-
Save Akhu/057e2a19e56be75e23d244dfcdc37846 to your computer and use it in GitHub Desktop.
Simple way to invert a mask on a layer with swift / quartzcore / ios
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
func mask(withRect rect: CGRect, inverse: Bool = false) { | |
let path = UIBezierPath(rect: rect) | |
let maskLayer = CAShapeLayer() | |
if inverse { | |
path.appendPath(UIBezierPath(rect: self.bounds)) | |
maskLayer.fillRule = kCAFillRuleEvenOdd | |
} | |
maskLayer.path = path.CGPath | |
self.layer.mask = maskLayer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe you just need to apply the gradient/opaque to the UIView you are masking.