Skip to content

Instantly share code, notes, and snippets.

@naotokui
Created November 13, 2012 04:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naotokui/4063901 to your computer and use it in GitHub Desktop.
Save naotokui/4063901 to your computer and use it in GitHub Desktop.
UIView RoundedCorner Category
#import <QuartzCore/QuartzCore.h>
@implementation UIView (UIView_RoundCorner)
- (void) setCornersRoundedWithRadius: (float) cornerRadius
{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.bounds
byRoundingCorners: UIRectCornerAllCorners
cornerRadii: CGSizeMake(cornerRadius, cornerRadius)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
self.layer.mask = maskLayer;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment