Ossir
Ossir

Reputation: 3145

How to force hugging UILabel content after orientation changes

I have two views (UILabels) on my view controller with next layout: layout

I want to recalculate constraints after device orientation is changed, so my top label should take only one line and bottom label should move up to keep the same offset from top label (top label is aligned vertically in container).

enter image description here

How can I achieve it?

If I try to use [self.toplabel sizeToFit]; it breaks all my size constraint to set new size and, that's important for me, neglect vertical space between these two labels.

I've tried:

[self.longLabel sizeToFit];

[self.botLabel layoutIfNeeded];
[self.botLabel setNeedsUpdateConstraints];
[self.botLabel updateConstraintsIfNeeded];
[self.botLabel needsUpdateConstraints];

But with no result. Constraint don't want to recalculate themselves.

enter image description here

Upvotes: 1

Views: 861

Answers (1)

Retro
Retro

Reputation: 4005

Did you try [label sizeToFit]; after change the Orientation.

You can call is with notification method after every orientation change

Upvotes: 1

Related Questions