Created
October 20, 2014 16:30
-
-
Save jparishy/b9179ad63518fc6d4d5b to your computer and use it in GitHub Desktop.
Inverted rounded rect mask for a view (content in the middle shown, outside part of rounded rect is set to white)
This file contains hidden or 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)configureInvertedRoundedRectMaskForView:(UIView *)view | |
{ | |
const CGFloat cornerRadius = 5.0f; | |
const CGRect rect = CGRectInset(view.bounds, 10.0f, 0.0f); | |
UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect:view.bounds]; | |
UIBezierPath *roundedRectPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius]; | |
[rectPath appendPath:roundedRectPath]; | |
CAShapeLayer *mask = [CAShapeLayer layer]; | |
mask.path = rectPath.CGPath; | |
mask.fillRule = kCAFillRuleEvenOdd; | |
view.layer.backgroundColor = [UIColor whiteColor].CGColor; | |
view.layer.mask = mask; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment