I have an UIImageView
created using Storyboard inside UIViewController
.
I'm trying to rescale the width of the image to fit the screen width and rescale height proportionally:
[fImage setImage:[UIImage imageNamed: @"f2345.jpeg"]];
[fImage sizeToFit];
fImage.contentMode = UIViewContentModeScaleAspectFit;
CGRect frame = filmImage.frame;
frame.size.width = [[UIScreen mainScreen] bounds].size.width;
// Alternative way to do the similar thing - gives the same result in my case
// frame.size.width = [[UIScreen mainScreen] applicationFrame].size.width;
fImage.frame = frame;
It then shows an image which is scaled but it fits some other area and there is a whitespace aruond my image.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.
An object that manages image data in your app.
Try using this code:
float imgFactor = frame.size.height / frame.size.width;
frame.size.width = [[UIScreen mainScreen] bounds].size.width;
frame.size.height = frame.size.width * imgFactor;
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