Skip to content

Instantly share code, notes, and snippets.

@samjarman
Created January 9, 2014 20:33
Show Gist options
  • Save samjarman/8341490 to your computer and use it in GitHub Desktop.
Save samjarman/8341490 to your computer and use it in GitHub Desktop.
Rounding corners on UIViews (and their subclasses, UIImageView, etc)
UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];
@sammcewan
Copy link

UIImageView *roundedView;
CALayer *roundedViewLayer;

roundedView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wood.jpg"]];

/**
 *  Get the animation layer of the view
 *  Note: To circumvent performance issues when animated we rasterise accordingly.
 */
roundedViewLayer = self.view.layer;
roundedViewLayer.masksToBounds = YES;
roundedViewLayer.cornerRadius = 10.0f;
roundedViewLayer.shouldRasterize = YES;
roundedViewLayer.rasterizationScale = [[UIScreen mainScreen] scale];

@samjarman
Copy link
Author

Thanks Sam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment