iOS Guides | Samples

MonoTouch.UIKit.NSLayoutConstraint Class

A relationship between two layout attributes used in a constraint-based layout.

See Also: NSLayoutConstraint

Syntax

[MonoTouch.Foundation.Register("NSLayoutConstraint", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 6, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
[MonoTouch.ObjCRuntime.Unavailable(MonoTouch.ObjCRuntime.PlatformName.WatchOS, MonoTouch.ObjCRuntime.PlatformArchitecture.All, null)]
public class NSLayoutConstraint : NSObject

Remarks

An NSLayoutConstraint specifies the relationship between two layout attributes (NSLayoutConstraint.FirstAttribute and NSLayoutConstraint.SecondAttribute, both of which are of type NSLayoutAttribute) in a constraint-based layout.

The relationship consists of:

The constraint engine will set the value of the NSLayoutConstraint.FirstAttribute such that it satisfies the constraint FirstAttribute <Relation> <Constant> + <Multiplier> * <SecondAttribute>. For instance, in the following code from the "Media Notes" sample, tconstraint2 is a constraint that specifies that the top of the toolbar is going to be equal to the top of the View plus the value of the toolbarVerticalOffset, while tconstraint1 specifies that the width of the toolbar will be equal to the width of the View. Both of these constraints have a NSLayoutConstraint.Priority of 1.0.

C# Example

var tconstraint2 = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Top, NSLayoutRelation.Equal,
                                                View, NSLayoutAttribute.Top, 1.0f, toolbarVerticalOffset);
toolbarTopConstraint = tconstraint2;
var tconstraint1 = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Width, NSLayoutRelation.Equal,
                                                View, NSLayoutAttribute.Width, 1.0f, 0.0f);

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.UIKit.NSLayoutConstraint are listed below.

See Also: NSObject

Public Constructors

Default constructor, initializes a new instance of this class.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

ActiveBoolean. Controls whether the constraint is active.  Active constraints are used as part of the auto-layout process, those that are not are ignored.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
ConstantSingle. Indicates the constant float applied to the constraint.
[read-only]
FirstAttributeNSLayoutAttribute. The attribute of the first item participating in the constraint.
[read-only]
FirstItemNSObject. The first item participating in the constraint.
[read-only]
MultiplierSingle. Applied to the second attribute participating in the constraint.
PrioritySingle. The priority of the constraint. Must be in range [0, UILayoutPriority.Required].
[read-only]
RelationNSLayoutRelation. The NSRelation that holds between the two items in the constraint.
[read-only]
SecondAttributeNSLayoutAttribute. The attribute of the second item participating in the constraint.
[read-only]
SecondItemNSObject. The second item participating in the constraint.
ShouldBeArchivedBoolean. Whether the constraint should be archived by its owning UIView.

Public Methods

static
ActivateConstraints(NSLayoutConstraint[])
Activates all of the constraints passed.
static
Create(NSObject, NSLayoutAttribute, NSLayoutRelation) : NSLayoutConstraint
Static factory method to create a constraint based on a UIView, an NSLayoutAttribute, and an NSLayoutRelation.
static
Create(NSObject, NSLayoutAttribute, NSLayoutRelation, Single, Single) : NSLayoutConstraint
Static factory method for creating a constraint.
static
Create(INativeObject, NSLayoutAttribute, NSLayoutRelation, INativeObject, NSLayoutAttribute, Single, Single) : NSLayoutConstraint
Factory method for creating a constraint.
static
DeactivateConstraints(NSLayoutConstraint[])
Deactivates all of the constraints passed.
static
FromVisualFormat(String, NSLayoutFormatOptions, params Object[]) : NSLayoutConstraint[]
Factory method for creating a constraint using Visual Format Language.
static
FromVisualFormat(String, NSLayoutFormatOptions, NSDictionary, NSDictionary) : NSLayoutConstraint[]
Factory method for creating a constraint using Visual Format Language.

Protected Methods

override
Dispose(Boolean)
Releases the resources used by the NSLayoutConstraint object.