I have two labels arranged horizontally in my TableViewCell. The right should use as much space as it needs, while the one on the should left use up the remaining space. In the case where the length of the two labels is greater than the width of the cell, the left label should be trimmed so that the right has enough space to fully display. The labels are aligned to their respective sides, if that makes a difference.
The "Arrange > Fill Container Vertically" option under the Size Inspector is similar to what I need for the left label, but I want it to only occupy space not needed by the right label.

If I add a constraint to the trailing space on the left label (see the third constraint below), the result is almost what I need, but instead of the right label being given the needed space, the left label takes the needed space (see final image).


I think this is easier than you might expect...
Constrain "LeftLabel" leading, constrain "RightLabel" trailing, constrain Horizontal Spacing between the two to >= 8, and then give "LeftLabel" a Content Compression Resistance Priority of Low (250).
That tells auto-layout to expand each label based on its text content, but if the distance between them ends up being less-than 8, let "RightLabel" expand to its text, but expand "LeftLabel" only to the point that it is 8-pts from "RightLabel".

Left Label selected:

Results:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With