<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSLayoutAnchor/constraint(lessThanOrEqualTo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLayoutAnchor(im)constraintLessThanOrEqualToAnchor:"
  },
  "title" : "constraint(lessThanOrEqualTo:)"
}
-->

# constraint(lessThanOrEqualTo:)

Returns a constraint that defines one item’s attribute as less than or equal to another.

```
func constraint(lessThanOrEqualTo anchor: NSLayoutAnchor<AnchorType>) -> NSLayoutConstraint
```

## Parameters

`anchor`

A layout anchor from an [`NSView`](/documentation/AppKit/NSView) or [`NSLayoutGuide`](/documentation/AppKit/NSLayoutGuide) object. You must use a subclass of [`NSLayoutAnchor`](/documentation/AppKit/NSLayoutAnchor) that matches the current anchor. For example, if you call this method on an [`NSLayoutXAxisAnchor`](/documentation/AppKit/NSLayoutXAxisAnchor) object, this parameter must be another [`NSLayoutXAxisAnchor`](/documentation/AppKit/NSLayoutXAxisAnchor).

## Return Value

An [`NSLayoutConstraint`](/documentation/AppKit/NSLayoutConstraint) object that defines the attribute represented by this layout anchor as less than or equal to the attribute represented by the `anchor` parameter.

## Discussion

This method defines the relationship `first attribute <= second attribute`. Where `first attribute` is the layout attribute represented by the anchor receiving this method call, and `second attribute` is the layout attribute represented by the `anchor` parameter. All values are measured in points; however, these values can be interpreted in different ways, depending on the type of layout anchor.

- For leading or trailing anchors, the values increase as you move in the current language’s reading direction. For English, values increase as you move to the right.
- For left and right anchors, the values increase as you move to the right.
- For [`NSLayoutYAxisAnchor`](/documentation/AppKit/NSLayoutYAxisAnchor) objects, the values increase as you move down.
- For [`NSLayoutDimension`](/documentation/AppKit/NSLayoutDimension) objects, the values increase as the items increase in size.

The constraints produced by the following two examples are identical.

```objc
// Creating a constraint using NSLayoutConstraint
[NSLayoutConstraint
 constraintWithItem:subview
 attribute:NSLayoutAttributeLeading
 relatedBy:NSLayoutRelationLessThanOrEqual
 toItem:self.view
 attribute:NSLayoutAttributeLeadingMargin
 multiplier:1.0
 constant:0.0].active = YES;
 
// Creating the same constraint using constraintLessThanOrEqualToAnchor:
NSLayoutGuide *margin = self.view.layoutMarginsGuide;
[subview.leadingAnchor constraintLessThanOrEqualToAnchor:margin.leadingAnchor].active = YES;
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)