Skip to content

Instantly share code, notes, and snippets.

@badeen
Created October 9, 2012 19:23
Show Gist options
  • Save badeen/3860863 to your computer and use it in GitHub Desktop.
Save badeen/3860863 to your computer and use it in GitHub Desktop.
Center image in image view if smaller than image view otherwise proportionally scale
@interface UIImage (ObjColumnist)
- (void)updateWithSpecialScaling;
@end
@implementation UIImage (ObjColumnist)
- (void)updateWithAdjustedScaling
{
CGSize imageSize = self.image.size;
if (imageSize.width > CGRectGetWidth(self.frame) || imageSize.height > CGRectGetHeight(self.frame)) {
self.contentMode = UIViewContentModeScaleAspectFit;
} else {
self.contentMode = UIViewContentModeCenter;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment