How to change bottom layout constraint in iOS, Swift

Joon. P picture Joon. P · Aug 19, 2015 · Viewed 35.5k times · Source

I have scroll view as @IBOutlet

@IBOutlet weak var mainScrollView: UIScrollView!

I want to change the

"Bottom space to: Bottom Layout Guide" 

constraint programmatically.

First Item : Bottom Layout Guide.Top
Relation : Equal
Second Item: Scroll View.Bottom
Constant: 0 -> 50 // (I want to change this programmatically)
Priority: 1000
Multiplier: 1

How can I do this?

Answer

Ashish Kakkad picture Ashish Kakkad · Aug 19, 2015

Take the constraint as IBOutlet of NSLayoutConstraint.

enter image description here

Set the constraint outlets and change constant value by :

self.sampleConstraint.constant = 20
self.view.layoutIfNeeded()