Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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