Reputation: 2034
I have a ViewController which has a tableview in it. I set its autolayout manually. Now I'm trying to change the autolayout constraints programmatically. How can I do that?
This is my code's screenshot
Thanks
Upvotes: 0
Views: 209
Reputation: 153
You can change constraints programatically without any outlet:
for (_, value) in self.view.constraints.enumerate() {
let constraint = value as NSLayoutConstraint
if constraint == .Height {
if value.firstItem.isEqual(self.tableView) {
constraint.constant = 200.0
}
}
}
Upvotes: 5
Reputation: 757
Follow these steps
eg. @IBOutlet weak var heightConstraint: NSLayoutConstraint!
update constant, heightConstraint.constant = 100.
Upvotes: 2
Reputation: 7552
Set up outlets for the constraints you need to modify and hook them up.
Upvotes: 0