Created
May 7, 2013 09:52
-
-
Save nek023/5531520 to your computer and use it in GitHub Desktop.
UIImageView+actualImageSize
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
@interface UIImageView (actualImageSize) | |
- (CGSize)actualImageSize; | |
@end |
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
#import "UIImageView+actualImageSize.h" | |
@implementation UIImageView (actualImageSize) | |
- (CGSize)actualImageSize | |
{ | |
CGSize actualImageSize; | |
CGFloat sx = self.frame.size.width / self.image.size.width; | |
CGFloat sy = self.frame.size.height / self.image.size.height; | |
CGFloat s = 1.0; | |
switch (self.contentMode) { | |
case UIViewContentModeScaleAspectFit: | |
s = fminf(sx, sy); | |
actualImageSize = CGSizeMake(self.image.size.width * s, self.image.size.height * s); | |
break; | |
case UIViewContentModeScaleAspectFill: | |
s = fmaxf(sx, sy); | |
actualImageSize = CGSizeMake(self.image.size.width * s, self.image.size.height * s); | |
break; | |
case UIViewContentModeScaleToFill: | |
actualImageSize = CGSizeMake(self.image.size.width * sx, self.image.size.height * sy); | |
break; | |
default: | |
actualImageSize = CGSizeMake(self.image.size.width * s, self.image.size.height * s); | |
break; | |
} | |
return actualImageSize; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment