-
-
Save martinpilch/a0cc9f8234c59a4323da to your computer and use it in GitHub Desktop.
Size of image in UIImageView
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 (ImageSize) | |
- (CGSize)imageSize; | |
@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+ImageSize.h" | |
@implementation UIImageView (ImageSize) | |
- (CGSize)imageSize { | |
CGSize imageSize = self.image.size; | |
CGSize imageViewSize = self.frame.size; | |
float widthScale = 1.0f; | |
float heightScale = 1.0f; | |
widthScale = imageViewSize.width / imageSize.width; | |
heightScale = imageViewSize.height / imageSize.height; | |
float scale = MIN(widthScale, heightScale); | |
imageSize.width *= scale; | |
imageSize.height *= scale; | |
return imageSize; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment