Last active
December 12, 2015 06:38
-
-
Save rais38/4730084 to your computer and use it in GitHub Desktop.
UIView with rounded corners
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
/** | |
@see http://www.dbsnippets.com/2012/09/11/objective-c-redondear-esquinas-de-un-uiview/ | |
You must import basic Core Animation classes | |
#import <QuartzCore/QuartzCore.h> | |
Example: | |
[self roundView:backgroundColorView onCorner:(UIRectCornerAllCorners) radius:10.0]; | |
[self roundView:imgView onCorner:(UIRectCornerTopLeft|UIRectCornerBottomLeft) radius:5.0]; | |
*/ | |
- (void)roundView:(UIView *)view onCorner:(UIRectCorner)rectCorner radius:(float)radius { | |
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds | |
byRoundingCorners:rectCorner | |
cornerRadii:CGSizeMake(radius, radius)]; | |
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; | |
maskLayer.frame = view.bounds; | |
maskLayer.path = maskPath.CGPath; | |
[view.layer setMask:maskLayer]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment