I have two views, v1 and v2, that are horizontally aligned inside a UIView. I want the views to have equal width. So I select the pin menu in auto-layout and select the width constraint. And then I go to the "Resolve Auto Layout Issues" menu and click on "Update Frames", but doing that just make my views v1 and v2 disappear. Does anyone know how I might get my views to have equal width? For comparison, in android I would place the views in a horizontal linear layout and give them both a weight of 1.
4 Answers
One of the views needs to have a fixed width, or the views need to be pinned to the edges of the superview and to each other so that you have a chain of constraints running from the left to the right edge of the superview. Once you have one of these two conditions, you can select both views and choose "Equal Widths" in the pin menu.

- 103,982
- 12
- 207
- 218
Is that the only constraint you're setting? XCode probably needs more information to avoid an ambiguous layout. In addition to "equal widths" you probably also need to pin the edges to the superview, set a distance between the 2 views, and perhaps try setting a min width constraint so they don't disappear. http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

- 3,750
- 19
- 24
-
I may need to set the min width you mentioned. I only see an option for fixed width in the auto-layout palette. How might I set a min-width? – Katedral Pillon Jul 25 '14 at 15:35
-
Under the "[measurements tab][1]" tab (right-side panel in interface builder), or in the view hierarchy panel to left of the storyboard, you can select/edit the individual constraints. In the options there you'll see ["Relation"][2] which you can set to "equal" "less than" or "greater than." Choose "greater than" to set a minimum value. [1]: http://www.techotopia.com/images/a/a2/Iso6_view_autolayout_settings.png [2]: https://developer.apple.com/library/prerelease/iOS/documentation/UserExperience/Conceptual/UIKitUICatalog/Art/xcode_auto_layout_attributes_inspector.png – mc01 Jul 25 '14 at 16:38
I'm sure that you could also select the two views, and in the "Alignment Constraints" select both "Leading Edges" and "Trailing Edges" constraints and then manually set the width of one and the other should follow suit.

- 46
- 2
I think anyone who comes to this Question and thread of answers should read the following answer too! It shows a simple way to do this.

- 1
- 1

- 7,983
- 3
- 57
- 80