Skip to content

Instantly share code, notes, and snippets.

@tdksk
Created November 27, 2014 13:30
Show Gist options
  • Save tdksk/21f6b821011398cc74f8 to your computer and use it in GitHub Desktop.
Save tdksk/21f6b821011398cc74f8 to your computer and use it in GitHub Desktop.
UIView maskByRoundingCorners:cornerRadius:
#import "UIView+TDKUtil.h"
@implementation UIView (TDKUtil)
- (void)maskByRoundingCorners:(UIRectCorner)corners
cornerRadius:(CGFloat)cornerRadius
{
[self layoutIfNeeded];
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
CAShapeLayer *maskLayer = [CAShapeLayer new];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment