Created
April 15, 2015 22:46
-
-
Save 0xMarK/08effddac69f502fcece to your computer and use it in GitHub Desktop.
Mask a hole inside a rect.
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
// Mask | |
CAShapeLayer *maskLayer = [CAShapeLayer layer]; | |
maskLayer.fillRule = kCAFillRuleEvenOdd; | |
maskLayer.frame = CGRectMake(0, 0, self.notificationsTabBarButton.frame.size.width, self.notificationsTabBarButton.frame.size.height); | |
CGPoint circleCenter = self.notificationsBadge.center; | |
CGFloat innerCircleRadius = self.notificationsBadge.frame.size.width/2; | |
CGFloat circleRadius = innerCircleRadius + 2; | |
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:circleCenter radius:circleRadius startAngle:0.0 endAngle:M_PI * 2.0 clockwise:YES]; | |
UIBezierPath *innerCirclePath = [UIBezierPath bezierPathWithArcCenter:circleCenter radius:innerCircleRadius startAngle:0.0 endAngle:M_PI * 2.0 clockwise:YES]; | |
UIBezierPath *path = [UIBezierPath bezierPathWithRect:maskLayer.frame]; | |
path.usesEvenOddFillRule = YES; | |
[path appendPath:circlePath]; | |
[path appendPath:innerCirclePath]; | |
maskLayer.path = path.CGPath; | |
self.notificationsTabBarButton.layer.mask = maskLayer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment