Skip to content

Instantly share code, notes, and snippets.

@atljeremy
Created December 5, 2013 14:33
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 atljeremy/7806014 to your computer and use it in GitHub Desktop.
Save atljeremy/7806014 to your computer and use it in GitHub Desktop.
A UIView Category for making round View's. Doesn't play nice with auto layout, for obvious reasons (direct frame manipulation).
@implementation UIView (Extras)
- (void)makeRound
{
self.contentMode = UIViewContentModeScaleAspectFill;
self.clipsToBounds = YES;
CGRect f = self.frame;
CGFloat w = CGRectGetWidth(f);
CGFloat h = CGRectGetHeight(f);
CGFloat corner = w;
if (h > w) { // Portrait Orientation
f.size.height = w;
} else if (w > h) { // Landscape Orientation
f.size.width = h;
corner = h;
}
self.frame = f;
self.layer.cornerRadius = (corner / 2);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment