Last active
October 26, 2016 18:39
-
-
Save almas73/d44ea39f03c75d0e673ced76b7f73d0c to your computer and use it in GitHub Desktop.
UIView cut hole
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
- (void)cutHole { | |
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; | |
CGMutablePathRef path = CGPathCreateMutable(); | |
CGFloat radius = self.holeView.frame.size.height / 2; | |
CGFloat x = self.holeView.frame.size.width / 2; | |
CGFloat y = self.holeView.frame.size.height / 2; | |
CGPathAddArc(path, nil, x, y, radius, 0.0, 2 * 3.14, false); | |
CGPathAddRect(path, nil, CGRectMake(0, 0, self.holeView.frame.size.width, self.holeView.frame.size.height)); | |
maskLayer.path = path; | |
maskLayer.fillRule = kCAFillRuleEvenOdd; | |
self.holeView.layer.mask = maskLayer; | |
self.holeView.clipsToBounds = YES; | |
CGPathRelease(path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment