Can AutoLayout equally place multiple buttons?

I am trying to create a view containing some buttons arranged vertically, and I would like the spaces between the buttons to be equal when the window is resized. Limitations (using the visual format) on this view:

H:|-0-[button1]-0-| H:|-0-[button2]-0-| H:|-0-[button3]-0-| H:|-0-[button4]-0-| V:|-0-[button1]-(>=0)-[button2]-(>=0)-[button3]-(>=0)-[button4]-0-| 

The buttons are displayed correctly, except that only one of the three spaces is taken into account, defined as> = 0, and the remaining spaces remain equal to zero (the layout is ambiguous).

Is there a way to set these three spaces equal using AutoLayout?

+8
cocoa osx-lion
source share
3 answers

Create invisible views between each pair of buttons, and then limit the width of these views to equal.

V: | - [Button1] [spacerView1] [button2] [spacerView2] [Button3] - |

Then create a constraint so that spacerViews have the same width and the constraint that the width of the first spacer view should be> = 0.

+10
source share

The Foreman is right, but I would like to add.

 V:|[button1][spacerView1(>=0)][button2][spacerView2(==spacerView1)][button3][spacerView3(==spacerView1)][button4]| 

Be a little more concise.

You do not need to set 0s between -s. The same goes for horizontal distance

 H:|[button1]| H:|[button2]| //etc... 
+4
source share

Instead of using autodetection restrictions, you should embed buttons in NSMatrix whose autoresizesCell set to YES . This will automatically process the interval without invisible gaps.

+3
source share

All Articles