UIImageView方面适合和居中 [英] UIImageView aspect fit and center
本文介绍了UIImageView方面适合和居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以编程方式声明的图像视图,并且正在以编程方式设置其图像.
I have an image view, declared programmatically, and I am setting its image, also programmatically.
但是,我发现自己无法将图像设置为既适合外观又使图像中心与图像视图对齐.
However, I find myself unable to set the image to both fit the aspect and align centre to the image view.
换句话说,我希望图像为:
In other words, I want the image to:
- 如果图像较大,请按比例缩小以适合外观.
- 如果图像很小,请居中,但不能放大.
我怎么得到的?
推荐答案
只需粘贴解决方案:
就像@manohar所说的
Just like @manohar said
imageView.contentMode = UIViewContentModeCenter;
if (imageView.bounds.size.width > ((UIImage*)imagesArray[i]).size.width && imageView.bounds.size.height > ((UIImage*)imagesArray[i]).size.height) {
imageView.contentMode = UIViewContentModeScaleAspectFit;
}
解决了我的问题
这篇关于UIImageView方面适合和居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文