App*_*Dev 2 height aspect-ratio uiscrollview uiimageview ios
我有一个视图,我需要放置一个UIImageView,我被告知将其放在一个矩形内,该矩形采用屏幕宽度,其高度小于宽度(固定大小).然而,我给出的图像或多或少是方形jpeg图像,因此想法是填充应包含图像的矩形的宽度,并以保持其纵横比的方式设置图像的高度.然后,我应该能够让用户垂直滚动图像以查看完整的图像.
我怎么能这样做?
提前致谢
编辑:我需要为具有不同大小的几个图像执行此操作,但这应该在视图中适合相同的矩形区域大小
您可以设置imageview内容模式.
imageView.contentMode = UIViewContentModeScaleAspectFit;
这将确保通过保持原始宽高比来显示图像.
编辑:
我想这就是你想要的:
UIImage *originalImage = [UIImage imageNamed:[picArr objectAtIndex:a]];
double width = originalImage.size.width;
double height = originalImage.size.height;
double apect = width/height;
double nHeight = 320.f/ apect;
self.img.frame = CGRectMake(0, 0, 320, nHeight);
self.img.center = self.view.center;
self.img.image = originalImage;
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.. :)
| 归档时间: |
|
| 查看次数: |
6601 次 |
| 最近记录: |