luky
luky

Reputation: 2370

Xcode pin bottom constraint doesnt work

Why the pin constraint doesnt work? I have no constraints, and I want to pin one view to bottom of main view, so I select the child view, then I click the icon from "w:Any h:Any row" in Interface Builder bottom right (Pin), then i click the bottom "I" to create bottom constraint, but if I resize the controller view (in design mode) the view is not moved but something like this appears: (The red line with number - instead of moving the blue view to bottom).

enter image description here

I have pinned it to "bottom layout guide". I also tried to pin it to "view" from dropdown while pinning, but that doesnt work too.

enter image description here

If I look on the "Issue navigator" there is only warning saying "Position and size are ambigious for View"

enter image description here

Upvotes: 0

Views: 557

Answers (2)

soan saini
soan saini

Reputation: 260

You need to define the position of view properly. So that constraints can define position and size of the object. Like in your case you have only provided constraint from the bottom, which will not be sufficient to define position. So you need to define either Height and Width constraints or top, left and right constraints.

And as long as long red line is being shown keep adding constraints.

Upvotes: 1

Alex Brown
Alex Brown

Reputation: 1613

Without any other other constraints there is no way for Xcode to know what you want to do with the view, all it knows is that you want the bottom of your subview to stay 99pts away from the bottom of the superview, but doesn't know what to do with the top, left, or right edges.

Try adding constraints for the remaining 3 edges, it can be as simple as setting the width and height (the options under the bottom edge in your screenshot), or something more complex depending on what you want to achieve.

Upvotes: 1

Related Questions