Search code examples
iosautolayoutswift4ios-autolayoutxcode10

How to position view.top to super.bottom with AutoLayout?


I'm working on my first iOS application, I want to position the top of a view at the bottom of an other one. How can I do it please?


Solution

    1. Place your views in your view Controller the way you want them to be laid out.
    2. Set the leading and trailing (left and right) constraints for each view.
    3. If you control click and drag from one view to another view you will see the following

      enter image description here

      In the picture above, the orange area and green area are two separate views, and I clicked on the green area, pressed control, and clicked on it and dragged to the orange area and released. Then the following will appear

    4. Click bottom, although this will need to be modified.

    5. Click on the constraint as seen in the picture below

      enter image description here

      Then you will see something similar to the following in the attribute inspector:

      enter image description here

    Notice how it says first item and second item, in this case, each one of those items is a view in our case. Set the bottom of the bottom view equal to the top and you are done!