将 UIImageView 与 contentMode AspectFill 和 Top 对齐

Align UIImageView with contentMode AspectFill AND Top

当我使用 AspectFill 时,图像将在图像视图中居中,顶部和底部被截断。但我希望它从顶部开始,而不是中心。我看到很多问题,但都是关于 AspectFit,而不是 AspectFill。无论如何都可以将 AspectFill 和 Top 应用于 UIImageView 的 contentMode?

我刚找到这个 UIImageViewAligned 并决定回答我自己的问题。它完美运行。

It is a subclass of UIImageView that allows you to customize the alignment of the displayed image inside the view's frame. This works even if the contentMode is set to AspectFit, AspectFill or ScaleToFill.