NSLayoutDimension: constraintLessThanOrEqualToConstant() method
The constraintLessThanOrEqualToConstant() method creates a constraint: this dimension is less than or equal to a constant (this dimension ≤ value).
Syntax
constraintLessThanOrEqualToConstant(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.constraintLessThanOrEqualToConstant(300);
c.isActive = true;
console.log(c.relation, c.constant, c.secondAnchor);Result: box is at most 300 pt wide. The console prints lessThanOrEqual 300 null.
Corresponding iOS API
-[NSLayoutDimension constraintLessThanOrEqualToConstant:].
See also
constraintEqualToConstant()constraintGreaterThanOrEqualToConstant()constraintLessThanOrEqualToAnchor(): comparing against another dimension