hp iOS Coder
hp iOS Coder

Reputation: 3234

Storyboard - dynamically change height of UIView

popup1

enter image description here

popup2

enter image description here

Is it possible to create single popup in storyboard & dynamically change - decrease/increase their height when error occurs (as shown in popup2)

I expect a correct approach to create such view.

Upvotes: 2

Views: 625

Answers (2)

Aaron
Aaron

Reputation: 6704

One way to achieve this easily is by using a vertical UIStackView in interface builder. For example, I have a simple stack view set up that contains two labels:

vertical stack view

Now, in your view controller you can simply set your error label to hidden or not and the stack view will dynamically take care of the rest. e.g:

Without hiding anything:

error label showing

Hiding error label:

[_errorLabel setHidden:YES];

Error label hidden

Upvotes: 4

Nikita Ermolenko
Nikita Ermolenko

Reputation: 2259

You can do it. Just put Error view in the middle of the popup and when error occurs change height of this view (error, heightConstraint.constant = 50, for example).

Then call

[self.view setNeedsUpdateConstraints];
[self.view updateConstraintsIfNeeded];

But important to note, that you should configure all constraints correctly that the popup view is stretched properly.

Upvotes: 0

Related Questions