UITableViewCell子类imageView不遵循大小约束

时间:2016-12-07 00:07:07

标签: ios swift uitableview autolayout

我有一个带有图像视图的自定义表格视图单元格。在.xib文件中,我将高度和宽度约束设置为23.然后我将其设置为图像。

在将它用作单元格时,图像不遵循23的约束。我已经尝试了将UIImageView的内容模式从缩放到填充,到适当的合适,以及其他各种各样的工作。我做错了什么?

My table view cell in xib. Notice the height and width constraints

The result

Add the size inspector and constraint

View debug Content mode on the profile image Showing that clips to bound and content mode

3 个答案:

答案 0 :(得分:0)

如果某些内容与布局过程发生冲突,自动布局可能会删除它认为合适的约束。 IB会自动将您的宽度和高度约束优先级设置为1000.当出现问题并且您看到您的约束被更改时,请检查调试日志,您可能会看到系统添加了一个名为UIView-Encapsulated-Layout-Height的约束,系统可能还删除了一些约束。

尝试点击IB中高度和宽度限制旁边的修改,并将其优先级设置为999而不是1000,并查看是否可以解决您的问题。

答案 1 :(得分:0)

我猜你的contentMode是中心的 尝试更改imageView的contentMode,如下所示: imageView.contentMode = UIViewContentModeScaleToFill;

答案 2 :(得分:0)

在IBOutlet中选中'剪辑到绑定'并使用

imageView.contentMode = UIViewContentModeScaleToFill;