如何管理UIImageView内容模式? [英] How to manage UIImageView content mode?
问题描述
我有一个具有一些固定矩形的UIImageView。但我的图像尺寸不固定。我想根据UIImageView的rect大小显示图像。无论图像的分辨率是大还是大,它都必须根据UIImageView的大小固定显示。我对使用以下资产很困惑。
I have an UIImageView with some fixed rect size. But my images are not fixed in size. I want to display images according to UIImageView's rect size. Whether image is big or large in resolution it must be in fixed display according to UIImageView's size. I am confused in using below assets.
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw
在autoresize掩码中设置什么?
他们的表现如何?
What to set in autoresize mask ? How do they behave ?
推荐答案
请尝试使用此代码,希望它能为您效劳。
Please try this code, Hope it will work for you.
设置 UIImageView
contentMode
到 UIViewContentModeScaleAspectFill
如下:
imageView.contentMode = UIViewContentModeScaleAspectFill;
设置UIImageView的autoresizingMask如下:
set autoresizingMask of UIImageView as below :
imageView.autoresizingMask =
( UIViewAutoresizingFlexibleBottomMargin
| UIViewAutoresizingFlexibleHeight
| UIViewAutoresizingFlexibleLeftMargin
| UIViewAutoresizingFlexibleRightMargin
| UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleWidth );
这篇关于如何管理UIImageView内容模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!