简体   繁体   中英

Storyboard - dynamically change height of UIView

popup1

在此处输入图片说明

popup2

在此处输入图片说明

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.

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:

垂直堆栈视图

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. eg:

Without hiding anything:

错误标签显示

Hiding error label:

[_errorLabel setHidden:YES];

错误标签已隐藏

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM