Skip to content

Instantly share code, notes, and snippets.

@martinpilch
Created December 6, 2012 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinpilch/a0cc9f8234c59a4323da to your computer and use it in GitHub Desktop.
Save martinpilch/a0cc9f8234c59a4323da to your computer and use it in GitHub Desktop.
Size of image in UIImageView
@interface UIImageView (ImageSize)
- (CGSize)imageSize;
@end
#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