Skip to content

Instantly share code, notes, and snippets.

@jparishy
Created October 20, 2014 16:30
Show Gist options
  • Save jparishy/b9179ad63518fc6d4d5b to your computer and use it in GitHub Desktop.
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)
- (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