8

我有一个UIImageView使用 Storyboard 里面创建的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;

然后它显示一个缩放的图像,但它适合其他一些区域,并且我的图像周围有一个空白。

4

1 回答 1

13

尝试使用此代码:

float imgFactor = frame.size.height / frame.size.width;
frame.size.width = [[UIScreen mainScreen] bounds].size.width;
frame.size.height = frame.size.width * imgFactor;
于 2012-09-13T10:40:34.567 回答