Search code examples
iosxcodeautolayoutstoryboard

Square Positioning Auto Layout


Whats the best practice to handle constraints for those squares (green and blue ones)? The four, blue ones, are all of the same size.

I've spent some hours trying to get the constraints right, but everytime it doesn't fit for the IPhoneSE and smaller devices.

How to set the constraints here?

enter image description here


Solution

  • You can achieve what you want the below way:

    1. Use two horizontal stackviews to hold 4 views.
    2. Embed both the stackviews into a vertical stackView.

    enter image description here

    I am attaching an image for your reference:

    Hope this helps. For any queries feel free to leave a comment.