Skip to content

Instantly share code, notes, and snippets.

@rais38
Last active December 12, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rais38/4730084 to your computer and use it in GitHub Desktop.
Save rais38/4730084 to your computer and use it in GitHub Desktop.
UIView with rounded corners
/**
@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