<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSLayoutDimension/constraint(lessThanOrEqualToConstant:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLayoutDimension(im)constraintLessThanOrEqualToConstant:"
  },
  "title" : "constraint(lessThanOrEqualToConstant:)"
}
-->

# constraint(lessThanOrEqualToConstant:)

Returns a constraint that defines the maximum size for the anchor’s size attribute.

```
func constraint(lessThanOrEqualToConstant c: CGFloat) -> NSLayoutConstraint
```

## Parameters

`c`

A constant representing the maximum size of the attribute associated with this dimension anchor.

## Return Value

An [`NSLayoutConstraint`](/documentation/UIKit/NSLayoutConstraint) object that defines a maximum size for the attribute associated with this dimension anchor.

## Discussion

This method defines the relationship `first attribute <= c`. Where `first attribute` is the layout attribute represented by the anchor receiving this method call.

The constraints produced by the following two examples are identical.

```objc
// Creating a constraint using NSLayoutConstraint
[NSLayoutConstraint
 constraintWithItem:self.button
 attribute:NSLayoutAttributeWidth
 relatedBy:NSLayoutRelationLessThanOrEqual
 toItem:nil
 attribute:NSLayoutAttributeNotAnAttribute
 multiplier:1.0
 constant:40.0].active = YES;
 
// Creating the same constraint using constraintLessThanOrEqualToConstant:
[self.button.widthAnchor constraintLessThanOrEqualToConstant: 40.0].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)