2 个并排 UILabel 的布局约束问题
Layout Constraint issues with 2 side by side UILabels
我有 2 个并排的 UILabel。右边的那个随着里面的内容变化(使用 sizeToFit)而增长,当它增长时,左边的应该缩小并根据需要截断。
以下是我当前的限制条件:
左边的标签:
Leading space to superview: 8
Width <= 156
Top space to superview: 0
Height: 32
Trailing space to right label: 8
正确的标签:
Trailing space to superview: 8
Width >= 0
Top space to superview: 0
Height: 32
Leading space to left label: 8
Leading space to superview <= 172
使用我这里的内容,右边的标签会按原样增长,但左边的标签不会收缩和截断里面的文本。我做错了什么?
编辑:两个标签都应具有静态高度。右边的标签宽度应该增加,左边的标签宽度应该缩小。
对于增长和收缩约束,每个 UIView 都有这种方法:
contentCompressionResistancePriorityForAxis:// For setup shrink constraints
contentHuggingPriorityForAxis:// For setup growing constraints
别忘了优先级。
p.s。故事板在每个视图的参数中具有相同的字段。
我有 2 个并排的 UILabel。右边的那个随着里面的内容变化(使用 sizeToFit)而增长,当它增长时,左边的应该缩小并根据需要截断。
以下是我当前的限制条件:
左边的标签:
Leading space to superview: 8
Width <= 156
Top space to superview: 0
Height: 32
Trailing space to right label: 8
正确的标签:
Trailing space to superview: 8
Width >= 0
Top space to superview: 0
Height: 32
Leading space to left label: 8
Leading space to superview <= 172
使用我这里的内容,右边的标签会按原样增长,但左边的标签不会收缩和截断里面的文本。我做错了什么?
编辑:两个标签都应具有静态高度。右边的标签宽度应该增加,左边的标签宽度应该缩小。
对于增长和收缩约束,每个 UIView 都有这种方法:
contentCompressionResistancePriorityForAxis:// For setup shrink constraints
contentHuggingPriorityForAxis:// For setup growing constraints
别忘了优先级。
p.s。故事板在每个视图的参数中具有相同的字段。