1

I'm building a universal application with XCode, and I'm following the procedure from the 3rd chapter of "Beginning iPhone Development with Swift".

I have a view with two buttons named "left" and "right", and a label with empty text. That's how they're positioned at the beginning:

enter image description here

Next I add some constraints. The steps are:

  1. I ctrl-drag from the label to the view, and add two constraints: "center horizontally in container" and "top space to top layout guide". Then I select the label and click on "update constraints".
  2. For both the left and right buttons, I add a constraint: "vertical center in container".
  3. I add a "pin" constraint to separate the left button of 32 points from the left, and the same goes for the right button (but I add a separation from the right).

To explain this last step, that's what I add for the left button:

enter image description here

And that's what I add for the right button:

enter image description here

Next, since there are some warning, I select both the right and left buttons, and click on "update frames". This is what I end up with:

enter image description here

The right button is 32 points beyond the right boundary of the screen, and when I run the application the button (obviously) appears cut out. The pin constraint of the right button got automatically updated to -32 instead of 32, and if I change it again I get an error, saying that two constraints are conflicting:

enter image description here

Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187
  • Did you delete the constraints and re-add? It looks like the first and second items are the wrong way round – Wain Mar 04 '15 at 22:23
  • Uncheck the Constraints to margins option, it can make some funny stuff if enabled. – Arbitur Mar 05 '15 at 00:19

1 Answers1

1

As per your question you need to set constraint left and right from textfiled as per image I’ve set below.

Set left constraint to textfield and left button.

enter image description here

Set right constraint to textfield and right button.

enter image description here

I've given top constraint to textfield,leading and trailing to textfield.

enter image description here

enter image description here

**RESULT : **

enter image description here

Hope this solves your issue.

Dhaivat Vyas
  • 2,926
  • 1
  • 16
  • 26