name to be displayed
name to be displayed

Reputation: 53

Working with constraints in storyboard and code

I have a button and a view, when the button is not appearing I want the view to be extended (using top constraint) to fill up the white space, the button appears I want the view to shrink to make room for the button. The problem is I am getting this error:

failed: caught "NSInvalidArgumentException", "NSLayoutConstraint for (null): Constraint must contain a first layout item"

I set constraints in storyboard, and declare the top constraint by this:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *containerTopConstraint;

This is how I change the value of the constraints:

[_containerTopConstraint setConstant:20];

How can I fix this error?

Upvotes: 0

Views: 82

Answers (1)

Craig Siemens
Craig Siemens

Reputation: 13266

I'd try putting your views inside of a UIStackView. It automatically repositions views when the isHidden property changes on one of them to take up the empty space.

Upvotes: 1

Related Questions