aelam
aelam

Reputation: 2916

how to quartern by auto layout

enter image description here Look at the image. (Run on iPhone6 Plus)

I want every image has same width and height and with same space on both sides.

What I have done is

  1. set the Leading space to 11
  2. every button have space >=6
  3. Trailing space to 11
  4. every button has a ratio 1:1 THEN it works as the image like

What I have found is(maybe incorrect)

  1. It's impossible to set a WEIGHT to views (LIKE LeanearLayout on Android)
  2. It's impossible to set a flexible space width for many buttons on the same line by auto-layout

These make me can't do what I want to.

I don't want the final answer is calculating the spacing and size rather than auto-layout -_-||

Does anyone can solve it by auto-layout?

Upvotes: 1

Views: 45

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90551

It's a bit primitive, but the standard solution is to use spacing views. That is, put views between your buttons. Add constraints to keep each button adjacent to the spacing views on either side of it. Add constraints to keep all of the spacing views the same width. Add constraints to keep all of the spacing views the same height and a constraint to keep one of them (and thus all of them) to some specific height, possibly 0.

Upvotes: 1

Related Questions