Search code examples
iosswiftautolayout

iOS - how to arrange multiple components vertically using AutoLayout?


I have design the screen like below image

enter image description here

I solved this method.. set Y position of RedView, set vertical spacing of GreenView, set vertical spacing of BlueView... But this method seems inefficient.

Need help to achieve following Task.

  1. Components should always be stacked based on the center regardless of number. (because the number of components can change by requirements of client.)
  2. Components have various height.

Is there a good way?


Solution

  • Use Stack View Buddy .. It will make your life a lot easier ..

    That will give you an idea how to use them

    https://www.raywenderlich.com/114552/uistackview-tutorial-introducing-stack-views

    Also go through the API Reference .. It will be helpful

    https://developer.apple.com/reference/uikit/uistackview

    They will automatically adjust themselves on item size changed or screen orientation changed ..