Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing constraints at runtime in swift

I'm really very weak in constraints part of ios. I have gone through many reference link as shown below but still not able solve my issue.

Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one

In case , i need to change the y-axis of UIView2 based on some condition. The storyboard.png shows the layout. enter image description here

If condition fails UIView2 with step1, step 2 and step3 should be visible and it's position should also change as shown in condition1.png

enter image description here

If condition pass UIView2 with step1, step 2 and step3 should not be visible as shown in condition1.png

enter image description here

Please provide me steps for how to achieve the above scenario. I tried it doing but if set the constraint for UIView1 the height remains same and does not change at runtime.

like image 286
cybergeeeek Avatar asked Oct 22 '25 02:10

cybergeeeek


1 Answers

Just make the outlet of the height constraint of both UIView and use constant property to change the height constraints like...

if conditionfails{
     heightconstOfView1.constant = 0
}
else{
    heightconstOfView2.constant = 0
}
like image 194
EI Captain v2.0 Avatar answered Oct 25 '25 04:10

EI Captain v2.0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!