如何调整UIImageView的大小以适合基础图像而不移动它? [英] How to resize a UIImageView to fit the underlying image without moving it?

查看:56
本文介绍了如何调整UIImageView的大小以适合基础图像而不移动它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIImageView,其框架在加载图像之前设置,对于该图像而言总是太大,因此,例如,当我尝试拐弯时,什么也没发生.

I have a UIImageView whose frame, set before the image is loaded, is always too large for the image, so when I try to round the corners, for example, nothing happens.

如何在确保UIImageView的中心点不变的情况下调整框架的大小,使其与基础图像的大小相同?

How can I resize the frame so it's the same size as the underlying image, while ensuring that the center point of the UIImageView does not change?

推荐答案

如果更改UIView的边界,则中心不会改变.

If you change the bounds of a UIView the center will not change.

CGRect bounds;

bounds.origin = CGPointZero;
bounds.size = newImage.size;

imageView.bounds = bounds;
imageView.image = newImage;

这篇关于如何调整UIImageView的大小以适合基础图像而不移动它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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