Skip to content

Instantly share code, notes, and snippets.

@almas73
Last active October 26, 2016 18:39
Show Gist options
  • Save almas73/d44ea39f03c75d0e673ced76b7f73d0c to your computer and use it in GitHub Desktop.
Save almas73/d44ea39f03c75d0e673ced76b7f73d0c to your computer and use it in GitHub Desktop.
UIView cut hole
- (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