gpt4 book ai didi

objective-c - 缩放 UIImageView 以适应屏幕宽度

转载 作者:太空狗 更新时间:2023-10-30 03:31:41 27 4
gpt4 key购买 nike

我在 UIViewController 中使用 Storyboard 创建了一个 UIImageView

我正在尝试重新缩放图像的宽度以适应屏幕宽度并按比例重新缩放高度:

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

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

最佳答案

尝试使用这段代码:

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

关于objective-c - 缩放 UIImageView 以适应屏幕宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12404299/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com