如何配置图像或图像视图,以便无论图像视图的大小如何,图像都保持其纵横比?

How to configure the image or image view so that the image keeps its aspect ratio no matter what the size of the image view is?

我将图像视图放在静态 table 视图单元格中。现在正在拉伸图像以适合整个视图。我希望图像:

首先我去了 UIImageView 的文档。但是没有找到任何有用的东西。然后我查看了UIImage的文档,发现了UIImageResizingMode。但是那个枚举只包含 StretchTile,这不是我想要的。然后我发现 this post 告诉我

logo.contentMode = .Center

但图像仍然被拉伸。然后我尝试了这个

logo.contentMode = .ScaleAspectFill

但结果是一样的

请告诉我一个好的方法!

附加信息:

图像视图具有以下限制:

您必须将 contentMode 设置为 UIViewContentModeScaleAspectFit