调整图像大小以适合比例 [英] Resize image to fit proportions

查看:60
本文介绍了调整图像大小以适合比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序设计中,我有一个正方形空间来存放来自远程服务器的图像.但是,有时图像是横向矩形而不是正方形.

In the design of my app, I have a square space for an image that comes from a remote server. However, occasionally the image is a landscape rectangle instead of a square.

我不想裁剪图像,而是将其缩放到足以适合正方形约束的程度,然后用一些背景色(也许是白色)填充剩余空间.

I don't want to crop the image, but instead scale it down far enough to fit inside the square constraints, then fill in the remaining space with some background color, white maybe.

推荐答案

UIImageView contentMode 设置为 UIViewContentModeScaleAspectFit .

这篇关于调整图像大小以适合比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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