Class
iOSLayoutConstraint
Description
Used to add new auto-layout constraints or modify existing ones.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
✓ |
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
firstItem As Object, firstAttribute As iOSLayoutConstraint, relation As iOSLayoutConstraint, secondItem As Object, secondAttribute As iOSLayoutConstraint, multiplier As Double, gap As iOSLayoutConstraint, priority As Double = 1000 |
|||
firstItem As Object, firstAttribute As iOSLayoutConstraint, relation As iOSLayoutConstraint, secondItem As Object, secondAttribute As iOSLayoutConstraint, multiplier As Double, addend As Double, priority As Double = 1000 |
Enumerations
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. |
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
iOSLayoutConstraint.Active
Active As Boolean
Indicates if this auto-layout rule is active.
De-activate an existing named constraint:
' "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
iOSLayoutConstraint.FirstAttribute
FirstAttribute As AttributeTypes
The attribute of the first control.
This property is read-only.
iOSLayoutConstraint.FirstItem
FirstItem As Object
The control to which the auto-layout rule applies.
This property is read-only.
iOSLayoutConstraint.Offset
Offset As Double
The offset that can be applied to the rule.
Change the offset (in this case the width) or an existing named constraint:
' "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
iOSLayoutConstraint.Priority
Priority As 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 |
iOSLayoutConstraint.Relation
Relation As 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.
iOSLayoutConstraint.Scale
Scale As Double
The scale (aka multiplier) for the rule.
This property is read-only.
iOSLayoutConstraint.SecondAttribute
SecondAttribute As AttributeTypes
The attribute to use from the second (related) control. This is the "Edge" item in the Inspector.
This property is read-only.
iOSLayoutConstraint.SecondItem
SecondItem As Object
The related control for the rule. This is the "Relative To" item in the Inspector.
This property is read-only.
iOSLayoutConstraint.StandardGap
StandardGap As 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.
Method descriptions
iOSLayoutConstraint.Constructor
Constructor(firstItem As Object, firstAttribute As iOSLayoutConstraint, relation As iOSLayoutConstraint, secondItem As Object, secondAttribute As iOSLayoutConstraint, multiplier As Double, gap As iOSLayoutConstraint, priority As Double = 1000)
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
Creates a new auto-layout rule for the firstItem control with a StandardGap offset value.
iOSLayoutConstraint.Constructor
Constructor(firstItem As Object, firstAttribute As iOSLayoutConstraint, relation As iOSLayoutConstraint, secondItem As Object, secondAttribute As iOSLayoutConstraint, multiplier As Double, addend As Double, priority As Double = 1000)
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
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:
' 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.
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
iOS projects on the iOS operating system.
See also
Object parent class; MobileScreen class; Creating screens that auto-resize using Auto Layout topic