0

我正在尝试显示包含缩略图和标题的行。

它适用于短标题字符串,但对于长字符串,它会中断。与其横向扩展,我更希望它纵向扩展。查看下面的屏幕截图,看看使用长字符串时会发生什么。我正在使用PureLayout来管理自动布局:

thumbnailView.autoSetDimensions(to:CGSize(width: 75, height: 75))
thumbnailView.autoPinEdge(toSuperviewEdge: .leading, withInset: kLabelHorizontalInsets)
thumbnailView.autoPinEdge(toSuperviewEdge: .top, withInset: kLabelVerticalInsets)
thumbnailView.autoPinEdge(toSuperviewEdge: .bottom, withInset: kLabelVerticalInsets, relation: .greaterThanOrEqual)

titleLabel.autoPinEdge(.leading, to: .trailing, of: thumbnailView, withOffset: kLabelHorizontalInsets, relation: .lessThanOrEqual)
titleLabel.autoPinEdge(toSuperviewEdge: .top, withInset: kLabelVerticalInsets)
titleLabel.autoPinEdge(toSuperviewEdge: .trailing, withInset: kLabelHorizontalInsets)
titleLabel.autoPinEdge(toSuperviewEdge: .bottom, withInset: kLabelVerticalInsets)

还设置了 UITextLabel 上的相应设置:

 titleLabel.lineBreakMode = .byWordWrapping
 titleLabel.numberOfLines = 0
 titleLabel.textAlignment = .left

任何建议表示赞赏。谢谢 表格视图截图

4

2 回答 2

1

您不需要限制顶部和底部约束。UILabel 会自动调整 contentHeight。可以参考contentHuggingPriorityForAxis:contentCompressionResistancePriorityForAxis:。您可以固定标签的中心而不是底部和顶部。

于 2017-03-13T01:34:25.657 回答
0

找到了一种可能的解决方案:解决方案

原来UILabelnumberOfLines属性和自动布局不能很好地配合。

于 2017-03-13T01:11:34.647 回答