缩放的UIImageView以适应屏幕宽度(Scaling UIImageView to fit s

2019-07-31 13:44发布

我有一个UIImageView利用内幕故事板创建UIViewController

我试图重新调整图像的宽度以适合屏幕的宽度和按比例重新调整高度:

[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;

然后,它显示了缩放图像,但它符合其他一些地区,有一个空白aruond我的形象。

Answer 1:

请尝试使用此代码:

float imgFactor = frame.size.height / frame.size.width;
frame.size.width = [[UIScreen mainScreen] bounds].size.width;
frame.size.height = frame.size.width * imgFactor;


文章来源: Scaling UIImageView to fit screen width