1

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?

Community
  • 1
  • 1
aelam
  • 2,796
  • 2
  • 27
  • 32
  • got the same problem... I don't know if its possible to solve it with autolayout or i'm finally going to set an outlet with a couple of constraints and calculate their value... – diegomen Oct 31 '14 at 07:51
  • 1
    Possible duplicate: http://stackoverflow.com/questions/13075415/evenly-space-multiple-views-within-a-container-view – The dude Oct 31 '14 at 08:18
  • @Thedude you are right, But it's hard to find it for me :( Thank you! – aelam Oct 31 '14 at 09:04

1 Answers1

1

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.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154