Justin
Justin

Reputation: 65

Auto layout isn't working as expected for laying out buttons?

I'm creating a scene in XCode in Main.storyboard where the user is able to choose between 5 options (buttons) and when I created the auto layout to horizontally center the buttons, as well as vertically space them 5 pixels apart:

On the 3.5 inch screen, the buttons take up most of the screen

On the 4 inch screen, the buttons take up about 3/4 of the screen

On the 4.7 inch screen, the buttons take up about half of the screen

It makes sense for this to be happening, but I created a @3x, @2x, and normal sized (1x) images using Prepo

The buttons have custom background image properties

How can I get the 4 inch, 4.5 inch, and even 5.5 inch screens on the iPhone to display like the 3.5 inch screen where the buttons take up most of the screen?

Upvotes: 0

Views: 102

Answers (1)

Christeena John
Christeena John

Reputation: 204

Set the following constraints for your buttons.

  1. For 1st button set constant top space to top layout guide (say 20px).
  2. For last button set constant bottom space to bottom layout guide (say 20px).
  3. Set equal heights for all buttons.

And you already have the following constraints.

  1. align buttons horizontally centre
  2. vertical spacing between them is 5px

So now buttons will adjust its height to take up most of screen space. Try this.

Upvotes: 1

Related Questions