Reputation: 1454
I am new to using Auto Layout and Size classes but I've done a lot or research on how it all works. While I understand it I still cannot figure simple things out. What I am trying to do is center the two buttons for all iPhones in portrait mode, while it looks good on the 5.5in screen it gets worse and as screen size decreases. I have found it very challenging to learn how to use Auto Layout so any help is much appreciated.
Upvotes: 0
Views: 400
Reputation: 6021
This bothered me as well, until I figured it out. Here's some hints:
Auto layout:
Your specific question:
Upvotes: 0
Reputation: 60150
Do you mean that you want them centered vertically? (It looks like they're already centered horizontally.)
My guess is that right now, you have a top spacing constraint to the top button. This gives you a fixed distance between the top button and the top of the screen, which is why the buttons push down further on smaller screens – the same distance represents a bigger proportion of a smaller screen.
Instead, you'll probably want a center Y constraint for one of the buttons. The quick way to build this as a proof of concept is to:
This is a quick Auto Layout system that gets both buttons close to the center of the screen, and maintains proportionality on smaller devices. Give it a shot and see if it does what you want.
If this seems about right, but you want the pair of buttons together to be centered (that is, you want the gap between them to fall directly on the center line of the screen), you'll probably want an extra container view enclosing both buttons. Then, you can pin the container view's center Y to its superview's center Y, and align the buttons to the container's top and bottom, respectively.
Hope that helps!
Upvotes: 1