Frage

I have 2 UILabel in a UIView:

[headerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[headerViewLabel]-[headerViewVersionLabel]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(headerViewVersionLabel, headerViewLabel)]];

I'm having trouble getting the headerViewLabel to take up more space then it is:

enter image description here

I want the "New" label to be as small as possible aka sizeToFit and let the "New Event" stretch out farther.

How can I do this?

SOLVED:

Thanks to Matt, I added increased the "New"'s priorityHugging:

[headerViewVersionLabel setContentHuggingPriority:251 forAxis:UILayoutConstraintAxisHorizontal];

and works like a charm:

enter image description here

War es hilfreich?

Lösung

First, you've omitted an important piece of the puzzle: you are not going to get the New Event to stretch unless you pin its left side, which you have neglected to do.

Second, the labels are both already trying (at a low level of priority) to size themselves to fit their text. It is impossible for them to do that and for them to be pinned at both ends and to one another.

The solution is to nudge the horizontal hugging priority of one of them, to be greater than the other. In your case, the New label needs a higher horizontal hugging priority; one point added will do. Keep the New Event label at its default horizontal hugging priority (probably 250) and set the New label to one point higher (probably 251).

Andere Tipps

I think if you change the justification of the new label to be right justified it will do what you want. At least it works for me setting it up in interface builder.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top