如何管理 UIImageView 内容模式? [英] How to manage UIImageView content mode?

查看:21
本文介绍了如何管理 UIImageView 内容模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个固定矩形大小的 UIImageView.但我的图像大小不固定.我想根据 UIImageView 的矩形大小显示图像.无论图像是大的还是分辨率的大,都必须根据 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

在自动调整大小掩码中设置什么?他们的行为如何?

What to set in autoresize mask ? How do they behave ?

推荐答案

请试试这个代码,希望它对你有用.

Please try this code, Hope it will work for you.

UIImageView contentMode 设置为 UIViewContentModeScaleAspectFill 如下:

set UIImageView contentMode to UIViewContentModeScaleAspectFill as below :

imageView.contentMode = UIViewContentModeScaleAspectFill;

设置 UIImageView 的 autoresizingMask 如下:

set autoresizingMask of UIImageView as below :

imageView.autoresizingMask =   
    ( UIViewAutoresizingFlexibleBottomMargin
    | UIViewAutoresizingFlexibleHeight
    | UIViewAutoresizingFlexibleLeftMargin
    | UIViewAutoresizingFlexibleRightMargin
    | UIViewAutoresizingFlexibleTopMargin
    | UIViewAutoresizingFlexibleWidth );

这篇关于如何管理 UIImageView 内容模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆