Arrange horizontal space between items in a bar using autolayout

I’m currently has a View like this, how can I setup the constraint to display the items equally like the Iphone 7 review in all size of screen?. I’ve tried so many constraint including stackView but no use. Thank you very much and have good day ahead.

You can use five view in the black view:

Constraint for first view:

  • leading space to superview : 0
  • Bottom and top space to superview : 0
  • trailing space to second view : 0

Constraint for second, third and fourth view:

  • leading space to left view : 0
  • Bottom and top space to superview : 0
  • trailing space to right view : 0
  • equal with and equal height with first view

Constraint for last(5th) view:

  • leading space to left view (4th) : 0
  • Bottom and top space to superview : 0
  • trailing space to superview : 0
  • equal with and equal height with first view

Then insert your button or element in these view with their constraint (eg. horizontal center / vertical center)

Use a UIToolbar which features a UIBarButtonSystemItemFlexibleSpace item that you can place in between your 5 regular items.

In Obj-C code you’d do something like:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.navigationController setToolbarHidden:NO];

    UIBarButtonItem* spaceItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                                target:self
                                                                                action:nil];

    ... create other items ...

    self.toolbarItems = @[ item1, spaceItem1, item2, spaceItem2, ... ];

    ...
}