Created
October 9, 2012 19:23
-
-
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
This file contains hidden or 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
@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