1

I need to stretch all buttons horizontally from:

[button1][button2]

to:

[  button1  ][  button2  ]

depend on width of screen.

So I have pinned button1 to superview for top and left edges. Then I pinned button2 to button1 horizontally and set equal height to button1 and also pinned button 2 to the right edges.

This is my issues right now:

enter image description here

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
  • So what's the problem? What result does that setup give you? The constraints you say you have, should do what you want. – rdelmar Dec 21 '14 at 19:59
  • so the storyboard says that I need to set horizontal hugging priority, but I am not sure how to make it. I change it for one button, but it still says that other button has issue with width. – Matrosov Oleksandr Dec 21 '14 at 20:01
  • @rdelmar, I have updated question with 2 button it will be simple to describe and answer on it – Matrosov Oleksandr Dec 21 '14 at 20:02
  • Pin one button to the superview then pin the other button to have the same center y and width as the first button. – rfj001 Dec 21 '14 at 20:06
  • The system needs to know which button to expand to take up the space, so that's why you get those requests. Do you want the buttons to all be the same size? – rdelmar Dec 21 '14 at 20:08
  • @rdelmar, yes I want them to be the same for example to have 160 pt width for one, if screen width is 320pt – Matrosov Oleksandr Dec 21 '14 at 20:10
  • 1
    Then select the two buttons, and choose "Equal Widths" from the pin menu. If you do that, then you shouldn't have to mess with the compression resistance values. – rdelmar Dec 21 '14 at 20:13

1 Answers1

4

You can do something like this:

Horizontal Constraints for the left button:
1. Leading of left button equals leading of superview.
2. Trailing of left button equals centerX of superview (See the last image below).

Horizontal Constraints for the right button:
1. Leading of right button equals trailing of left button.
2. Trailing of right button equals trailing of superview.

Note: Put the vertical constraints according to what you want.

Here's a sample screenshot:

View Layout

Constraints

Left Button Constraint

Ganesh Kamath
  • 1,181
  • 11
  • 20