0

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
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223

3 Answers3

2

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.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
  • The bottom was 646 not 686 my mistake. I fixed it. What I did: -removed bottom constraints -set the height a constant. thank you – newbiejava1998 Oct 03 '17 at 10:02
0

It's not preferable to have such a huge value for any constraint. So when changing devices, the height of screens may change and your constraints will break.

The preferred way will be to create a Height constraint and set it to 686 and don't set the bottom constraint as it's not needed anymore. But the problem can arise here if the screen size is smaller, as the views on the bottom will not be visible. To overcome this you should make use of a scrollview and put this content view inside scroll view.

Abhishek Jain
  • 826
  • 8
  • 20
0

you can set the Height constraint of View instead of bottom constraint
or you can use the Size classes