30

In Xcode 6, I could use the Editor menu to Pin:

  • Leading Space to Superview
  • Trailing Space to Superview
  • Top Space to Superview
  • Bottom Space to Superview

I can't find a way to do this in Xcode 7 beta. If I press the Align button in the Storyboard view, I see:

  • Leading Edges
  • Trailing Edges
  • Top Edges
  • Bottom Edges

Which I assume is the same thing, but they are all greyed out.

Adding these 4 constraints in Xcode 6 would have taken about 20 seconds, but it took me 30 minutes to put it in Xcode 7 and can't figure it out.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Casey Perkins
  • 1,853
  • 2
  • 23
  • 41

5 Answers5

17

Unfortunately they removed this option from the Editor Menu but there is a drop-down menu. There you can select another view to which you can assign your margins. enter image description here.

Mobile Developer
  • 5,730
  • 1
  • 39
  • 45
  • This is close, but still does not work correctly. For instance, I put my left and right constraints relative to the superview as 20 on each side, but the XCode "expects" an X position of 36. This makes no sense. – Casey Perkins Oct 02 '15 at 17:44
  • After doing the above, select the constraint, pick the item from the first item or second item drop down, uncheck `Relative to Margin`. – jday Oct 18 '15 at 21:28
  • can we see it as default value? There were so many raw design template are designed for the whole view not just only top layout guide. – Ryan Chou Jul 23 '16 at 13:34
10

To pin Top, Bottom, Leading, and Trailing to the Superview, do this:

  1. Select the view.
  2. Click the Pin button (looks like a TIE Fighter).
  3. Under Add New Constraints, uncheck Constrain to margins.
  4. Click the left, right, and top and bottom beams.

If you click Add Constraints button, it will pin top, leading, and trailing to the Superview, and bottom to the Bottom Layout Guide. If you want to pin bottom to the Superview also, press the drop down arrow next to the bottom value and choose View instead of Bottom Layout Guide. Then click Add Constraints.

Casey Perkins
  • 1,853
  • 2
  • 23
  • 41
4

Well, I also meet this problem in Xcode 7.2, and have found out a way to solve it.

In Xcode 7.2 (and perhaps also in your version of Xcode), firstly select the view that you want to add constraint to, and then press the "control" button on your keyboard and keep doing it, and then drag the view to the super-view. Then a menu will appear, and then you can select to add some constraints. After adding the constraint you can release the "control" button. Note that the direction you drag will affect the available constraints at this time. For example, if you drag left, then the trailing constraint may be unavailable.

zhoudu
  • 623
  • 8
  • 19
1

Right next to the Align button is Pin button where you can set what you want.

Pin

a developer
  • 149
  • 2
  • 10
  • 5
    This only allows you to pin to the nearest neighbor, there doesn't seem to be a way to pin to the superview anymore in xcode 7. – Trianna Brannon Sep 22 '15 at 19:03
  • It does allow you to pin to the superview, but it gets the positioning wrong. See my comment to MaciekWrocław for details. – Casey Perkins Oct 02 '15 at 17:46
0

When you add a constraint via Add New Constraints you have a choise:

  • By default Xcode uses Safe Area - Align Top To
  • If you select a superview - Top Space To
yoAlex5
  • 29,217
  • 8
  • 193
  • 205