NSLayoutAnchor<AnchorType> Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Generates NSLayoutConstraint objects based on the value of the NSLayoutConstraint associated with this.
[Foundation.Register("NSLayoutAnchor", true)]
public class NSLayoutAnchor<AnchorType> : Foundation.NSObject, Foundation.INSCoding, Foundation.INSCopying, IDisposable where AnchorType : NSObject
[<Foundation.Register("NSLayoutAnchor", true)>]
type NSLayoutAnchor<'AnchorType (requires 'AnchorType :> NSObject)> = class
inherit NSObject
interface INSCoding
interface INativeObject
interface IDisposable
interface INSCopying
Type Parameters
- AnchorType
Whether the generating anchor is an NSLayoutXAxisAnchor, an NSLayoutYAxisAnchor, or an NSLayoutDimension.
- Inheritance
- Derived
- Attributes
- Implements
Remarks
The NSLayoutAnchor<AnchorType> class, introduced in iOS 9, allows layout constraints to be specified in code, in a fluent manner. For example:
blueView = new ContentView(UIColor.Blue);
view.AddSubview(blueView);
blueView.TranslatesAutoresizingMaskIntoConstraints = false;
var blueConstraints = new []
{
blueView.LeadingAnchor.ConstraintEqualTo(greenView.LeadingAnchor),
blueView.TrailingAnchor.ConstraintEqualTo(greenView.TrailingAnchor),
blueView.TopAnchor.ConstraintEqualTo(greenView.BottomAnchor, 10.0f),
blueView.HeightAnchor.ConstraintEqualTo(greenView.HeightAnchor),
blueView.WidthAnchor.ConstraintEqualTo(greenView.WidthAnchor)
};
NSLayoutConstraint.ActivateConstraints(blueConstraints);
In this example, the newly-created blueViewNSView has its height, width, leading, and trailing anchors defined as equal to that of a previously-defined greenView while its TopAnchor is set to be 10 logical pixels below the greenView's BottomAnchor.
Constructors
| Name | Description |
|---|---|
| NSLayoutAnchor<AnchorType>(NativeHandle) |
A constructor used when creating managed representations of unmanaged objects. Called by the runtime. |
| NSLayoutAnchor<AnchorType>(NSCoder) |
A constructor that initializes the object from the data stored in the unarchiver object. |
| NSLayoutAnchor<AnchorType>(NSObjectFlag) |
Constructor to call on derived classes to skip initialization and merely allocate the object. |
Properties
| Name | Description |
|---|---|
| Class | (Inherited from NSObject) |
| ClassHandle |
The Objective-C class handle for this class. |
| ConstraintsAffectingLayout | |
| DebugDescription | (Inherited from NSObject) |
| Description | (Inherited from NSObject) |
| ExposedBindings | (Inherited from NSObject) |
| Handle |
Handle (pointer) to the unmanaged object representation. (Inherited from NSObject) |
| HasAmbiguousLayout | |
| IsDirectBinding | (Inherited from NSObject) |
| IsProxy | (Inherited from NSObject) |
| Item | |
| Name | |
| RetainCount | (Inherited from NSObject) |
| Self | (Inherited from NSObject) |
| Superclass | (Inherited from NSObject) |
| SuperHandle |
Handle used to represent the methods in the base class for this NSObject. (Inherited from NSObject) |
| Zone | (Inherited from NSObject) |