IOS 自动布局 - UILabel 扩展到特定点

IOS Auto Layout - UILabel expand to certain point

我有一个 UITableViewCell,其中包含一个扩展到我设置的文本的 UILabel。我希望标签仅扩展到 UIImageView 的底部,而不是进一步扩展。

现在,如果文本很长,它会 运行 在底部按钮后面。谢谢

您可以像这样在代码中构建约束:

let constraint = NSLayoutConstraint(item: videoNameLabel, attribute: .Bottom, relatedBy: .LessThanOrEqual,toItem: thumbnailImageView, attribute: .Bottom, multiplier: 1, constant: 0)
videoNameLabel.addConstraint(constraint)

或者在故事板中做同样的事情:

而不是从标签底部到按钮的小于或等于约束,使其大于或等于,具有任何最小垂直常数 space 你想要在标签和按钮之间。