NSLayoutDimension: constraintEqualToConstant() method
The constraintEqualToConstant() method creates a constraint: this dimension equals a constant (this dimension = value).
Syntax
constraintEqualToConstant(value)Parameters
value
A number, in pt. Converted with Number().
Return value
A new NSLayoutConstraint. It isn't active yet; it takes part in layout only after it's activated with NSLayoutConstraint.activateConstraints() or isActive. The constraint's secondAnchor is null, and its secondAttribute is 'notAnAttribute'.
Exceptions
TypeError
value can't be converted to a finite number: constant must be a finite number, got "abc".
Examples
js
const box = new UIView();
const c = box.widthAnchor.constraintEqualToConstant(60);
c.isActive = true;
console.log(c.relation, c.constant, c.secondAnchor);Result: box is 60 pt wide. The console prints equal 60 null.
Corresponding iOS API
-[NSLayoutDimension constraintEqualToConstant:].
See also
constraintGreaterThanOrEqualToConstant()constraintLessThanOrEqualToConstant()constraintEqualToAnchor(): comparing against another dimension