Search code examples
iosiphonenslayoutconstraint

Constraints in Swift not working


I'm trying to add some constraints to my view, but everytime I switch the device, the view goes crazy. How can I fix this?

How I want it to look and how it looks like on the iPhone 8 Plus:

How I want it to look and how it looks like on the iPhone 8 Plus

How it looks like when I switch to iPhone SE:

How it looks like when I switch to iPhone SE

I added these constraints:

  • 0 top
  • 0 left
  • 0 right
  • 686 bottom

Solution

  • If your bottom constraint is larger than the height of the device, naturally, it will be out of bounds.

    Moreover, your constraints will be ambiguous if the screen's height is smaller than 686.

    You'll need to have a height constraint with a constant of 50 to set up on the view rather than a bottom constraint.