UIImageView 不遵守 UITableViewCell 内部的约束

UIImageView not honouring constraints inside UITableViewCell

我有一个简单的 UITableViewController,tableview 设置为静态,我里面只有一个 UITableViewCell,UITableViewCell 有一个 UIImageView 和一个标签。

添加的约束如下

当我 运行 这个应用程序时,一切看起来都很好,除了图像没有保持正方形,这是因为 UIIMageView 放松了它的宽度和高度限制并显示了整个图像。使用的比例类型是纵横比填充。不确定结果是什么

如何使 UiImageView 遵循约束?

从情节提要中将 clipsToBounds 设置为 true,或者您也可以通过编程方式将其设置为:

imageView.clipsToBounds = true;

这将解决您的问题。