简而言之:
content Hugging Priority:压缩比优先级
content Compression Resistance Priority:抗压缩比优先级
场景使用在当两个内容不确定的控件要同一行显示,这时候就需要用到这两个条件要确保当两个控件宽度>屏幕宽度要压缩谁。
实例:
在同一行有两个UILabel控件,左边的label显示全部内容,而右边的label会自动根据剩余的宽度自动显示多行。
左边的约束:

右边的约束:

通过以上约束后,我们会发现存在约束错误,这是因为两个宽度不确定的控件出现了内容约束问题。


解决方法:
要保证左边的内容全部显示:那么它的压缩比优先级(content Hugging Priority)小于 右边
抗压缩比优先级(content Compression Resistance Priority)大于 右边
这里我们修改左边的这两个约束优先级,右边的保持不变

最终就可以完美展示出来:
网友评论