I have my UIImageView and I put an image into it that I resize like this:
UIImageView *attachmentImageNew = [[UIImageView alloc] initWithFrame:CGRectMake(5.5, 6.5, 245, 134)]; attachmentImageNew.image = actualImage; attachmentImageNew.backgroundColor = [UIColor redColor]; attachmentImageNew.contentMode = UIViewContentModeScaleAspectFit;
I tried getting the width of the resized picture in my UIImageView
by doing this:
NSLog(@"Size of pic is %f", attachmentImageNew.image.size.width);
But it actually returns me the width of the original picture. Any ideas on how do I get the frame of the picture that I see on screen?
EDIT: Here's how my UIImageView
looks, red area is its backgroundColor
I don't know is there more clear solution, but this works:
float widthRatio = imageView.bounds.size.width / imageView.image.size.width; float heightRatio = imageView.bounds.size.height / imageView.image.size.height; float scale = MIN(widthRatio, heightRatio); float imageWidth = scale * imageView.image.size.width; float imageHeight = scale * imageView.image.size.height;
A solution in Swift:
let currentHeight = imageView.bounds.size.height let currentWidth = imageView.bounds.size.width let newWidth = UIScreen.mainScreen().bounds.width let newHeight = (newWidth * currentHeight) / currentWidth println(newHeight)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With