首页 > UIImageview aspectfit with autolayout

UIImageview aspectfit with autolayout

如图:我将 UILabel 和 UIImageView 填充到一个 ContainerView 中,采用 AutoLayout 布局,设置了 UILabel 和 UIImageView 左边距和宽度的约束,同时设置 UIImageView 的 ContentMode 为 AspectFit,让其保持比例显示,但是最终的效果是 UIImageView 的高度比原始的图片高出许多(图中空白区域)。
注:ImageView 的内容为动态加载,所以不能提前设置 UImageView 的 Frame。

问:如何使用 AutoLayout 将 UIImageView 的高度约束到图片的高度?

【热门文章】
【热门文章】