将 UIImageView 与 contentMode AspectFill 和顶部对齐

Posted

技术标签:

【中文标题】将 UIImageView 与 contentMode AspectFill 和顶部对齐【英文标题】:Align UIImageView with contentMode AspectFill AND Top 【发布时间】:2015-11-04 09:25:23 【问题描述】:

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

【问题讨论】:

【参考方案1】:

我刚刚找到这个UIImageViewAligned 并决定回答我自己的问题。效果很好。

它是 UIImageView 的子类,允许您自定义视图框架内显示图像的对齐方式。即使 contentMode 设置为 AspectFit、AspectFill 或 ScaleToFill,这也有效。

【讨论】:

以上是关于将 UIImageView 与 contentMode AspectFill 和顶部对齐的主要内容,如果未能解决你的问题,请参考以下文章

如何将 UIView 中绘制的像素与 UIImageView 中的图像结合起来,并将其保存为新图像?

将 UIImageView 添加到 UITableViewCell?

iOS:将 UIImageView 对齐到顶部

iOS 8 UITableViewCell 与 UIImageView 动态高度

UIButton 的大小与封闭的 UIImageView 对象不同

将 UIImages 高度缩放到 UIImageView 高度