swiftios-autolayout

How to auto Layout Labels


I want to layout my labels like this using auto layout. It works fine in iPad 10.5. But when I move to any other versions of iPad with a larger screen, this design brokes. Anyone, please help me to solve this problem.


Solution

  • Swift 4

    Use stack view

    Step 1. insert labels inside of stack view like that

    enter image description here

    Step 2. add constraints on stack view from top, bottom, left and right alignment according to your requirement like that ->

    enter image description here

    Step 3. Use Stackview properties

    a.) set axis of Stack view Horizontally as well as vertically.

    b.) set alignment according to requirements.

    c.) set Distribution according to requirements (here i used fill equally).

    b.) set Spacing between labels .

    See here ->

    enter image description here

    Now run. it will work, it will show same in all Device like iPhone and iPad and also (horizontal and vertical).

    it will show like this(iPhone6splus)

    enter image description here