UIKit.UIView.AddConstraints Method
Adds multiple constraints to the layout of the receiving view or its subviews.

Syntax

[Foundation.Export("addConstraints:")]
[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_6_0)]
public virtual void AddConstraints (NSLayoutConstraint[] constraints)

See Also

UIView.Constraints
UIView.AddConstraint
UIView.RemoveConstraint
UIView.RemoveConstraints
UIView.TranslatesAutoresizingMaskIntoConstraints

Parameters

constraints
An array of UIKit.NSLayoutConstraints to add. The constraints must refer only to the receiving view or its subviews.

Remarks

The constraints must refer only to the receiving view or its subviews.

In the following example, Visual Format Language specifies that the blueView be horizontally attched to the leading and trailing edge (sides), that the blueView and greenView be vertically attached to the leading and trailing edges (top and bottom) and separated by 30 pixels, and that the greenView be the same width as the blueView and attached to both the leading and trailing edges. The result is shown in the following image.

C# Example

mainView.AddSubview(blueView);
mainView.AddSubview(greenView);

greenView.TranslatesAutoresizingMaskIntoConstraints = false;
blueView.TranslatesAutoresizingMaskIntoConstraints = false;

var viewsDictionary = NSDictionary.FromObjectsAndKeys(new NSObject[] { greenView, blueView}, new NSObject[] { new NSString("green"), new NSString("blue")});
var metrics = new NSDictionary();

mainView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-[blue]-|",0, new NSDictionary(), viewsDictionary));
mainView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-[blue]-(==30)-[green(==blue)]-|",0, new NSDictionary(), viewsDictionary));
mainView.AddConstraints(NSLayoutConstraint.FromVisualFormat("|-[green(==blue)]-|",0, new NSDictionary(), viewsDictionary));
              

Requirements

Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0