0

I have a view in my storyboard. By default I have set the view height to "0". Based upon my condition I need to modify the height of view to a certain height and give greater than or equal to constraint. I have tried according to this link.

Is there is a way to create constraint greater than or equal relation through code.

But it is not working in my case.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Swapna
  • 127
  • 1
  • 10
  • Show us some code to understand what have you done so far. With this description, we are clueless. – Rob Jan 21 '20 at 06:59
  • take IBOutlet of height and modify height using myHeightConstraint.constant = extraHeight and You also may need to call self.view.layoutIfNeeded(). – Ruchi Makadia Jan 21 '20 at 07:01
  • **By default I have set the view height to "0"** <- As a storyboard constraint? If yes, you'll have to have an IBOutlet of that to rely on changes through code. If you create another code equivalent of the same, you'll end up having conflicting constraints – Lokesh SN Jan 21 '20 at 07:21

2 Answers2

0

I think you want to programmatically update a height from 0 to a dynamic value of your choice right?

I would do it as follows:

  1. Create a height constraint of the view and assign it to 0. (You can do it in Storyboard or programmatically).
  2. Link the constraint to your class if you did it in Storyboard.
  3. In your code, update the constraint as follows. constraintName.constant = 400. Note it's a CGFloat.
Philip
  • 206
  • 2
  • 4
  • Yes, But I need to give greater than or equal to constraint programatically and not a constant value. – Swapna Jan 21 '20 at 08:38
  • Don't give an equal relation to the height constraint in storyboard instead use greater than or equal to relation in the storyboard itself. – soumil Jan 21 '20 at 09:51
0

Add the outlet of height constraint into your class. var heightConstraint: NSLayoutConstraint= 0

Then update the constraint constant value. self.heightConstraint.constant = 100 self.view.layoutIfNeeded()

Catherine
  • 199
  • 6