Class

# iOSLayoutConstraint

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to add new auto-layout constraints or modify existing ones.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                   | Type                                                 | Read-Only | Shared |
|--------------------------------------------------------|------------------------------------------------------|-----------|--------|
| `Active<ioslayoutconstraint.active>`                   | `Boolean</api/data_types/boolean>`                   |           |        |
| `FirstAttribute<ioslayoutconstraint.firstattribute>`   | `AttributeTypes<ioslayoutconstraint.attributetypes>` | ✓         |        |
| `FirstItem<ioslayoutconstraint.firstitem>`             | `Object</api/data_types/additional_types/object>`    | ✓         |        |
| `Offset<ioslayoutconstraint.offset>`                   | `Double</api/data_types/double>`                     |           |        |
| `Priority<ioslayoutconstraint.priority>`               | `Double</api/data_types/double>`                     | ✓         |        |
| `Relation<ioslayoutconstraint.relation>`               | `RelationTypes<ioslayoutconstraint.relationtypes>`   | ✓         |        |
| `Scale<ioslayoutconstraint.scale>`                     | `Double</api/data_types/double>`                     | ✓         |        |
| `SecondAttribute<ioslayoutconstraint.secondattribute>` | `AttributeTypes<ioslayoutconstraint.attributetypes>` | ✓         |        |
| `SecondItem<ioslayoutconstraint.seconditem>`           | `Object</api/data_types/additional_types/object>`    | ✓         |        |
| `StandardGap<ioslayoutconstraint.standardgap>`         | `Integer</api/data_types/integer>`                   | ✓         | ✓      |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                            | Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Returns | Shared |
|-------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
| `Constructor<ioslayoutconstraint.constructor0>` | firstItem As `Object</api/data_types/additional_types/object>`, firstAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, relation As `RelationTypes<ioslayoutconstraint.relationtypes>`, secondItem As `Object</api/data_types/additional_types/object>`, secondAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, multiplier As `Double</api/data_types/double>`, gap As `Integer</api/data_types/integer>`, priority As `Double</api/data_types/double>` = 1000  |         |        |
| `Constructor<ioslayoutconstraint.constructor1>` | firstItem As `Object</api/data_types/additional_types/object>`, firstAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, relation As `RelationTypes<ioslayoutconstraint.relationtypes>`, secondItem As `Object</api/data_types/additional_types/object>`, secondAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, multiplier As `Double</api/data_types/double>`, addend As `Double</api/data_types/double>`, priority As `Double</api/data_types/double>` = 1000 |         |        |

## Enumerations

<div id="ioslayoutconstraint.attributetypes">

<div class="rst-class">

forsearch

</div>

</div>

iOSLayoutConstraint.AttributeTypes

### AttributeTypes

> Defines the part of the control that will be used for comparison.
>
> | Enum           | Description                                                                                                          |
> |----------------|----------------------------------------------------------------------------------------------------------------------|
> | None           | No constraint.                                                                                                       |
> | Left           | The left position of the control.                                                                                    |
> | Right          | The right position of the control.                                                                                   |
> | Top            | The top position of the control.                                                                                     |
> | Bottom         | The bottom position of the control.                                                                                  |
> | Leading        | The edge that is the start of text in the current locale (English: left, Hebrew: right).                             |
> | Trailing       | The edge that is the end of text in the current locale (English: right, Hebrew: left).                               |
> | Width          | The width of the control.                                                                                            |
> | Height         | The height of the control.                                                                                           |
> | CenterX        | Horizontal center                                                                                                    |
> | CenterY        | Vertical center                                                                                                      |
> | Baseline       | Bottom of text that does not drop down (like g, p, j, etc). For non-text controls it is the same as the bottom edge. |
> | LeftMargin     | The left value padded with the standard margin size.                                                                 |
> | RightMargin    | The right value padded with the standard margin size.                                                                |
> | TopMargin      | The top value padded with the standard margin size.                                                                  |
> | BottomMargin   | The bottom value padded with the standard margin size.                                                               |
> | LeadingMargin  | The leading value padded with the standard margin size.                                                              |
> | TrailingMargin | The trailing value padded with the standard margin size.                                                             |

<div id="ioslayoutconstraint.relationtypes">

<div class="rst-class">

forsearch

</div>

</div>

iOSLayoutConstraint.RelationTypes

### RelationTypes

> The ways in which a property of a control is compared to property of another control.
>
> | Enum               | Description                                                                  |
> |--------------------|------------------------------------------------------------------------------|
> | LessThanOrEqual    | The value must be less than or equal to the value of the related control.    |
> | Equal              | The value must be equal to the value of the related control.                 |
> | GreaterThanOrEqual | The value must be greater than or equal to the value of the related control. |

## Property descriptions

<div id="ioslayoutconstraint.active">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.Active

**Active** As `Boolean</api/data_types/boolean>`

> Indicates if this auto-layout rule is active.
>
> De-activate an existing named constraint:
>
> ``` xojo
> ' "TAWidth" is a width constraint for a TextField that has been given
> ' a name in the auto-layout Inspector properties.
> Var c As iOSLayoutConstraint = Self.Constraint("TAWidth")
> c.Active = False
> ```

<div id="ioslayoutconstraint.firstattribute">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.FirstAttribute

**FirstAttribute** As `AttributeTypes<ioslayoutconstraint.attributetypes>`

> The attribute of the first control.
>
> This property is read-only.

<div id="ioslayoutconstraint.firstitem">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.FirstItem

**FirstItem** As `Object</api/data_types/additional_types/object>`

> The control to which the auto-layout rule applies.
>
> This property is read-only.

<div id="ioslayoutconstraint.offset">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.Offset

**Offset** As `Double</api/data_types/double>`

> The offset that can be applied to the rule.
>
> Change the offset (in this case the width) or an existing named constraint:
>
> ``` xojo
> ' "TAWidth" is a width constraint for a TextField that has been given
> ' a name in the auto-layout Inspector properties.
> Var c As iOSLayoutConstraint = Self.Constraint("TAWidth")
> c.Offset = 200
> ```

<div id="ioslayoutconstraint.priority">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.Priority

**Priority** As `Double</api/data_types/double>`

> The priority of the rule.
>
> This property is read-only.
>
> Higher priority constraints are met before lower priority constraints.
>
> | Priority    | Value |
> |-------------|-------|
> | Highest     | 1000  |
> | High        | 800   |
> | Medium-High | 600   |
> | Medium      | 400   |
> | Low         | 200   |

<div id="ioslayoutconstraint.relation">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.Relation

**Relation** As `RelationTypes<ioslayoutconstraint.relationtypes>`

> The type of relation between the first control and the second control. This is the "Is" item in the Inspector.
>
> This property is read-only.

<div id="ioslayoutconstraint.scale">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.Scale

**Scale** As `Double</api/data_types/double>`

> The scale (aka multiplier) for the rule.
>
> This property is read-only.

<div id="ioslayoutconstraint.secondattribute">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.SecondAttribute

**SecondAttribute** As `AttributeTypes<ioslayoutconstraint.attributetypes>`

> The attribute to use from the second (related) control. This is the "Edge" item in the Inspector.
>
> This property is read-only.

<div id="ioslayoutconstraint.seconditem">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.SecondItem

**SecondItem** As `Object</api/data_types/additional_types/object>`

> The related control for the rule. This is the "Relative To" item in the Inspector.
>
> This property is read-only.

<div id="ioslayoutconstraint.standardgap">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.StandardGap

**StandardGap** As `Integer</api/data_types/integer>`

> Used to supply a standard gap value when creating a new auto-layout rule. This item can only be used for the gap parameter in the constructor. It has no defined type.
>
> This property is read-only.
>
> This property is `shared</api/language/shared>`.

## Method descriptions

<div id="ioslayoutconstraint.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.Constructor

**Constructor**(firstItem As `Object</api/data_types/additional_types/object>`, firstAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, relation As `RelationTypes<ioslayoutconstraint.relationtypes>`, secondItem As `Object</api/data_types/additional_types/object>`, secondAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, multiplier As `Double</api/data_types/double>`, gap As `Integer</api/data_types/integer>`, priority As `Double</api/data_types/double>` = 1000)

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates a new auto-layout rule for the firstItem control with a StandardGap offset value.

<div id="ioslayoutconstraint.constructor1">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLayoutConstraint.Constructor

**Constructor**(firstItem As `Object</api/data_types/additional_types/object>`, firstAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, relation As `RelationTypes<ioslayoutconstraint.relationtypes>`, secondItem As `Object</api/data_types/additional_types/object>`, secondAttribute As `AttributeTypes<ioslayoutconstraint.attributetypes>`, multiplier As `Double</api/data_types/double>`, addend As `Double</api/data_types/double>`, priority As `Double</api/data_types/double>` = 1000)

> Creates a new auto-layout rule for the firstItem control with an addend offset value.
>
> Adds a right constraint to a TextField with an offset of 50 at the highest priority:
>
> ``` xojo
> ' RightConstraintField.Right = Self.Right + 50
> Var right As New iOSLayoutConstraint(RightConstraintField, _
>    iOSLayoutConstraint.AttributeTypes.Right, _
>    iOSLayoutConstraint.RelationTypes.Equal, _
>    Self, iOSLayoutConstraint.AttributeTypes.Right, _
>    1.0, 50, 1000)
> ```

## Sample code

This example adds a new button and constraints to the screen.

``` xojo
Var button As New MobileButton
button.Caption = "OK"
Self.AddControl button

' Applying constraints to the screen (Screen1), so they set the position and size of the button when displayed
' (size and position = centered with a margin of 50 points from the parent view edges)

Var RightC As New iOSLayoutConstraint(button,iOSLayoutConstraint.AttributeTypes.Right, iOSLayoutConstraint.RelationTypes.Equal, _
self, iOSLayoutConstraint.AttributeTypes.Right,1.0,-50)

Var LeftC As New iOSLayoutConstraint(button,iOSLayoutConstraint.AttributeTypes.left, iOSLayoutConstraint.RelationTypes.Equal, _
self, iOSLayoutConstraint.AttributeTypes.Left,1.0,50)

Var TopC As New iOSLayoutConstraint(button,iOSLayoutConstraint.AttributeTypes.Top, iOSLayoutConstraint.RelationTypes.Equal, _
self, iOSLayoutConstraint.AttributeTypes.Top,1.0,50)

Var BottomC As New iOSLayoutConstraint(button,iOSLayoutConstraint.AttributeTypes.Bottom, iOSLayoutConstraint.RelationTypes.Equal, _
self, iOSLayoutConstraint.AttributeTypes.bottom,1.0,-50)

Self.AddConstraint RightC
Self.AddConstraint LeftC
Self.AddConstraint TopC
Self.AddConstraint BottomC
```

## Compatibility

|                       |        |
|-----------------------|--------|
| **Project Types**     | Mobile |
| **Operating Systems** | iOS    |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `MobileScreen</api/user_interface/mobile/mobilescreen>` class; `Creating screens that auto-resize using Auto Layout</topics/user_interface/ios/creating_screens_that_auto-resize_using_auto_layout>` topic

</div>
