0

I am trying to emulate the attribute in Android android:layout_weight="1" in iOS.

I have a View with 7 Buttons and I want that they all have the same width and the same margin between them. In Android you will put weight 1 for all of them and marginLeft = 5 (except the last one having margin right).

How I can do this on iOS with the interface builder?

George
  • 25,988
  • 10
  • 79
  • 133
D4rWiNS
  • 2,585
  • 5
  • 32
  • 54

2 Answers2

2

You would use auto layout for this. For the leftmost object, set the leading edge to superview. For the rest of the objects, connect the trailing edge of one to the leading edge of the next. On the rightmost object, set the trailing edge to superview.

Check out this tutorial for the many many details.

http://www.raywenderlich.com/83129/beginning-auto-layout-tutorial-swift-part-1

Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
  • Hi I cant see the Autoresizing view in size inspector , I am using X-code 6 and the use AutoLayout is checked in Interface Builder Dcoument any idea? – D4rWiNS May 22 '15 at 10:53
  • 1
    If you look in the tutorial, you'll notice that the controls for auto layout are not in the inspector, but beneath the actual view. – Jeff Wolski May 22 '15 at 11:22
0

This answer worked for me: https://stackoverflow.com/a/26323745/1463931

The key is to nest your views in a StackView, now while holding down the Shift key, select the views you want to assign weights to,

then under the Constraints settings, select Equal Heights, or Equal Width depending our your desired outcome, save it.

Now open up the this Equal Heights constraints from the list on the top left corner of your StoryBoard (Where all your views and constraints are listed).

from the right section, edit the Multiplier value. This is where you enter the ratio of how you want your views to be distributed. Good luck.

kc ochibili
  • 3,103
  • 2
  • 25
  • 25