Using Auto Layout, how do I make two labels on the same "line" be dynamic in their widths (adjusting with how wide each one needs to be)?

Doug Smith picture Doug Smith · Oct 19, 2013 · Viewed 7k times · Source

Say I have two UILabels, one is a URL and one is a timer:

[http://website.com/link/to/specific/story] [9m 42s]

But the "timer" UILabel changes width a lot. Sometimes it is just 12s for example, other times it is 125h 32m 8s. There's a lot of variability. I want the timer UILabel to take up as much width as it needs and the URL label to take up the rest. This means if the timer is longer, shorter URLs, etc.

How do I do this in Auto Layout? Preferably in Interface Builder?

Answer

hybridcattt picture hybridcattt · Oct 19, 2013

You should set the compression resistance, URL label must have lower value;

Set the horizontal space between labels to constant (for example zero or default);

Set width for each label and select "less than" or "greater that" relation, these values set limits for shrinking/expanding of the view.