0

How to center two middle squares with autolayout to preserve equal spaces between all of them?

pic

Actually, i can outlet constraints and set it with computations involving container width and so on, but maybe there is some more smart way?

user1261347
  • 315
  • 2
  • 15

1 Answers1

2

My approach, with Interfacebuidler, is using "spacer views"

Spacer views are UIView that I have set to match widths equally.

Autolayout - vertically

.1. Black frames are UIViews

.2. UIImageView are squares

.3. Set equals width beetween spacer views

.4. Set equals width beetween squares

.4. Add edge constraints beetween spacer views and squares

.5. Set spacer view to transparent

If you need more detail to do that with Interface builder or by the code you should read this post :

Evenly space multiple views within a container view

Hope this can help you ;)

Community
  • 1
  • 1
Kevin Machado
  • 4,141
  • 3
  • 29
  • 54