Created
December 5, 2013 14:33
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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