Specify fixed size, aspect ratio, and position constraints

Use the Add New Constraints tool () to quickly create fixed size, aspect ratio, or position constraints for one or more views.

Add constraints using the Add New Constraints tool

  1. In Interface Builder, select one or more views by clicking them in the outline view or on the canvas.

    To select multiple views either:

    • Shift-click a range of views in the outline view

    • Command-click individual views in the outline view

    • Shift-click or Command-click individual views on the canvas

  2. At the bottom of the canvas, click the Add New Constraints tool button in the layout bar.

  3. In the Add New Constraints tool, set the properties of the constraints you want to add.

    See other tasks in this help topic for examples.

    Note: The Add New Constraints tool enables only valid constraint options for the selected views.

  4. From the Update Frames pop-up menu, choose an update option.

    None: Don’t update any frames.

    Update only the frames of the selected views: Choose “Items of New Constraints.”

    Update all frames in the container view: Choose “All Frames in Container.”

  5. Click Add Constraints (the title changes depending on the number of constraints you specify).

    The constraints are added to the selected views and appear in the outline view. The canvas updates the Auto Layout lines and badges.

Set a fixed distance to a neighboring view

  1. In the Add New Constraints tool, select the dashed red line corresponding to the side of the nearest neighbor.

  2. In the adjacent text field, choose a spacing option.

    Specify a fixed distance to the nearest neighbor: In the text field, enter the distance in points.

    Use the recommended spacing between views: Choose Use Standard Value from the pop-up menu.

    Use the current value: Choose Use Current Canvas Value from the pop-up menu.

    Choose a nearby neighbor: Choose a view below the line in the pop-up menu.

Set the width or height of one or more views

Set an aspect ratio constraint

Align two or more views

  1. In the Add New Constraints tool, select the Align checkbox.

    You must select two or more views to enable the Align checkbox.

  2. In the Align pop-up menu, choose an alignment attribute.

    Choose one of these values:

    • Leading Edges

    • Trailing Edges

    • Top Edges

    • Bottom Edges

    • Baselines

    • Horizontal Centers

    • Vertical Centers

    Note: The Baselines attribute is available only if all the selected views have baselines.

You can also align views using the Align tool.

SEE ALSOAuto Layout GuideSpecify distance and alignment constraintsFind and resolve Auto Layout errors and warnings