Reputation: 423
I have placed a small UIView
in my viewController
and set its constraints
left, right and bottom. In order not to get a constraint error
I have to add a height as well. I don't want to keep this height though, as I would like it to be dynamically set in its viewController
like this:
bottomBar.frame.size.height = self.view.frame.height / 10
I thought this would override
the constraint
value I set in the storyBoard
but it doesn't work. I have set it to / 2
just to see what happens, but it still keeps the storyboard
value. How do I override
this?
Upvotes: 1
Views: 392
Reputation: 506
You can create an IBOutlet connection from that constraint you added in your storyboard to the ViewController. ForExample in below image:
Once you have a connection you could do like:
self.newlyAddedConstraint.constant = self.view.frame.height / 10;
Thats all. your height will be adjusted. Depending on where you are setting this constant you might also need to call
[self.view layoutIfNeeded]
Upvotes: 1
Reputation: 2256
You can remove storyboard constraint at build time. Just choose needed constraint and select "Remove at build time".
Upvotes: 0
Reputation: 4608
You can link you storyboard height constraint to an outlet:
@IBOutlet var heightConstraint: NSLayoutConstraint!
then later you can change it:
heightConstraint.constant = 100
Upvotes: 1