RobertJoseph
RobertJoseph

Reputation: 8158

Using Auto Layout to distribute views uniformly in a superview

I've laid out this view hierarchy in IB (Xcode 6.3.1):

enter image description here

I would like to use Auto Layout (FYI: I am new to Auto Layout) to distribute the subviews horizontally (their widths should always be equal to each other).

I'd really appreciate any pointers... the constraints I've added thus far have not kept the widths of the subviews equal.

Upvotes: 0

Views: 70

Answers (1)

Cyrille
Cyrille

Reputation: 25144

You should add these constraints:

  • width of green == width of white
  • width of white == width of gray
  • leading space of green (to superview) == 8
  • horizontal space between green and white == 8
  • horizontal space between white and gray == 8
  • trailing space of gray (to superview) == 8

And you'll be good to go.

No need to specify that width of green == width of gray, they are already related to width of white, that'd be redundant, and autolayout hates redundancy.

Upvotes: 2

Related Questions