JackPearse
JackPearse

Reputation: 2942

Is it possible to align 3 Views side by side with same width in auto layout by only using interfacebuilder?

I have a quick question according auto layout. Maybe I am missing something, but since two hours I am trying to align 3 views next to each other with same width. My goal is that each view is using 1/3 of the screens with. After autorotation all views should have each the same width, but all views next to each other should have a total width of the superview.

My idea looks like this:

enter image description here

Doing this programmatically is kind of easy. Is it possible to solve this task by only using interface builder?

Upvotes: 5

Views: 2627

Answers (2)

André Slotta
André Slotta

Reputation: 14030

  1. set the three views to have an equal width
  2. set view1's leading constraint to superview to have a constant of 0
  3. set view1's trailing constraint to view2 to have a constant of 0
  4. set view2's trailing constraint to view3 to have a constant of 0
  5. set view3's trailing constraint to superview to have a constant of 0

Upvotes: 4

Stefan Salatic
Stefan Salatic

Reputation: 4523

Yes just set it as the same size as parent view (then change it to 1:3 ratio) and set leading constraints to 0. You do this by ctrl dragging the view you want to it's super view. There you select the Equal Widths property.

Like this, but 1:3 ratio

enter image description here

Upvotes: 6

Related Questions