Auto Layout? What does AUTO mean again?


I am trying to learn this auto layout, which is anything but AUTO!

So I have a single view app with a image view centered both horizontal/vertically that makes up my background. Then I have 9 buttons that I have placed 78 x 88 pixel images in. I want to have my app work in landscape and portrait. I have pinned the button in place with no issue. But I can not get then to correctly size in either landscape or portrait with out skewing the image or not all showing on the screen. Does anyone know how I can fix this issue? Does anyone have a tutorial on adding multiple buttons with images to a layout? Paul can you make a multi-button tutorial.

Other question should I be adding images to buttons or should I just stack the button on top of a image View? I don’t know and after several days beating my head against the wall I thought I would ask for help.

Thanks in advance


First of all if you have a specific image on the button - you need to either set specific Height and Width to the buttons or set Aspect Ratio. Right click and drag from the button to itself diagonally and you should be able to set that.
Also if you have multiple buttons that you want working in different orientations you might want to look into a StackView tutorial - there are a ton out there.


Thank you I am looking into stackView now. So this brings me to ask “Paul per apple we should start layouts using StackView. So why in every online swift training course I have seen constraints are reviewed and taught before StackView? Is it out of habit, or is it that old lesson of here is the hard way to do it, then I will show you the easy way?” Which if it is, then a person should learn objective c before swift, right? I am not criticizing as much as I am asking, “Why learn constraints before StackView, when you still have to use constraints with StackView.” It would just seem 1000 times easier to learn StackView first and teach constraints inside of the StackView lessons. It’s just my opinion.


Stackview is somewhat new. Personally I only use stackviews if I have multiple elements, like 5-10 buttons or labels…etc.
Otherwise I prefer setting my own constraints for each element.


Auto Layout is rule based, so you have to get the rules correct for it to work.

You also need to set the images to use Aspect Fit or Aspect Fill so that the image itself doesn’t stretch or skew. That’ll maintain the image aspect ratio.

Checkout Chapter 2, I covered a lot on Auto Layout and had a multi-button layout code exercise that would help you.

I find StackView to be more challenging to work with, unless you want three items in a row or a single column.

Any complex layout using StackViews in my opinion becomes very hard to work with without a deeper understanding of Auto Layout constraints, in addition to content hugging, stretching, and priorities.

My other frustration with StackView is that it hides content sometimes depending on what you put in it, which requires that you set constraints (you can’t avoid constraints) to get your views to reappear.