NSLayoutYAxisAnchor
NSLayoutYAxisAnchor represents a vertical position anchor: topAnchor, bottomAnchor, centerYAnchor, firstBaselineAnchor, and lastBaselineAnchor on a view or layout guide. It can only form constraints with another NSLayoutYAxisAnchor.
Inheritance: EventTarget → NSObject → NSLayoutAnchor → NSLayoutYAxisAnchor
Constructor
Can't be created with new. Read it from an anchor property on a view or a UILayoutGuide.
Instance methods
Also inherits constraintEqualToAnchor(), constraintGreaterThanOrEqualToAnchor(), and constraintLessThanOrEqualToAnchor() from NSLayoutAnchor.
Creating constraints with the system standard spacing. The standard spacing is a spacing defined by the system; the system decides its value based on what is at each end. The exact value is not verified in the simulator:
| Method | Resulting constraint |
|---|---|
constraintEqualToSystemSpacingBelowAnchor() | This anchor is below other, at a distance = standard spacing × multiplier |
constraintGreaterThanOrEqualToSystemSpacingBelowAnchor() | This anchor is below other, at a distance ≥ standard spacing × multiplier |
constraintLessThanOrEqualToSystemSpacingBelowAnchor() | This anchor is below other, at a distance ≤ standard spacing × multiplier |
The distance between two anchors:
| Method | Description |
|---|---|
anchorWithOffsetToAnchor() | Returns an NSLayoutDimension that represents the distance from this anchor to other |
Examples
const parent = new UIView();
const left = new UIView();
const right = new UIView();
for (const v of [left, right]) {
v.translatesAutoresizingMaskIntoConstraints = false;
parent.addSubview(v);
}
const next = right.topAnchor.constraintEqualToSystemSpacingBelowAnchor(left.bottomAnchor);
next.isActive = true;Effect: right sits below left, separated by the system standard spacing. Not verified in the simulator.
Corresponding iOS API
| ObjC | JS |
|---|---|
[b.topAnchor constraintEqualToSystemSpacingBelowAnchor:a.bottomAnchor multiplier:1] | b.topAnchor.constraintEqualToSystemSpacingBelowAnchor(a.bottomAnchor) |
[a.bottomAnchor anchorWithOffsetToAnchor:b.topAnchor] | a.bottomAnchor.anchorWithOffsetToAnchor(b.topAnchor) |
See also
NSLayoutAnchor: methods shared by all three kinds of anchor, and which anchors can form constraints with each otherNSLayoutConstraint