Search code examples
autolayoutxcode7ios-autolayout

Xcode 7 add trailing/leading/top/bottom constraints


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.


Solution

  • 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.