Skip to content

Instantly share code, notes, and snippets.

@jagregory
Created January 22, 2013 10:54
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 jagregory/4593780 to your computer and use it in GitHub Desktop.
Save jagregory/4593780 to your computer and use it in GitHub Desktop.
Category to add CSS border-radius style corner radii, where you can specify which corners to round.
@interface UIView(Corners)
- (void)cornerRadius:(float)radius forCorners:(UIRectCorner)corners;
@end
#import <QuartzCore/QuartzCore.h>
#import "UIView+Corners.h"
@implementation UIView(Corners)
-(void)cornerRadius:(float)radius forCorners:(UIRectCorner)corners{
CAShapeLayer* mask = [CAShapeLayer layer];
mask.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(radius, radius)].CGPath;
self.layer.mask = mask;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment