Created
November 27, 2014 13:30
-
-
Save tdksk/21f6b821011398cc74f8 to your computer and use it in GitHub Desktop.
UIView maskByRoundingCorners:cornerRadius:
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
#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