如何在 UIImageView 中获取缩放的 UIImage 的大小?
问题描述
UIImageView
的image.size
属性给出了原始UIImage
的大小.我想知道将自动缩放图像放入 UIImageView
时的大小(通常小于原始图像).
The image.size
attribute of UIImageView
gives the size of the original UIImage
. I would like to find out the size of the autoscaled image when it is put in the UIImageView
(typically smaller than the original).
例如,我将图像设置为 Aspect Fit
.现在我想知道它在屏幕上的新高度和宽度,以便在新缩放的图像上准确地绘制.
For example, I have the image set to Aspect Fit
. Now I want to know its new height and width on the screen so I can draw accurately on the new scaled image.
有没有什么方法可以做到这一点,而无需自己根据 UIImageView 的大小来解决?UIImage 原始大小(基本上是对其缩放进行逆向工程)?
Is there any way to do this without figuring it out myself based on the UIImageView size & UIImage original size (basically reverse engineering its scaling)?
推荐答案
Objective-C:
斯威夫特 4:
这篇关于如何在 UIImageView 中获取缩放的 UIImage 的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!