简体   繁体   中英

How to change constraints programmatically that is added from storyboard?

I have one screen. It will display like below

在此输入图像描述

Now When User clicked I have an Account and Password(button) it will display like below

在此输入图像描述

I want to move both views accordingly I added constraints using storyboard.Now need to change constraints from programming..

You need to create an IBOutlet of your constraint.
在此输入图像描述

Then you set the constant value of your constraint in code:

labelWidthConstraint.constant = newValue

If you want it animated you can do something like this:

Swift

labelWidthConstraint.constant = newValue
UIView.animate(withDuration: 0.3, animations: { 
    self.view.layoutIfNeeded()
})

Objective-C

self.labelWidthConstraint.constant = newValue;
[UIView animateWithDuration:0.3 animations:^{        
    [self.view layoutIfNeeded];
}];

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