以编程方式获取 UIImageView 的宽度和高度问题

Get UIImageView's width and height programmatically issue

我正在尝试使用以下代码

检索 iPhone 不同尺寸的图像视图的宽度和高度
print(self.imageLength.bounds.size.height)
print(self.imageLength.bounds.size.width)

是的,它 return 与 iPhone 5、iPhone 6、iPhone 6 加上相同的值 128.0。但界面上显示的 UIImage 会根据 phone 大小的不同而发生变化。有人知道为什么吗?

这里是图片限制条件

你可以试试这个

let imgWidth = myImageView.layer.frame.width
let imgHeight = myImageView.layer.frame.height

print(imgWidth)
print(imgHeight)