<!--
{
  "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(equalTo:multiplier:constant:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLayoutDimension(im)constraintEqualToAnchor:multiplier:constant:"
  },
  "title" : "constraint(equalTo:multiplier:constant:)"
}
-->

# constraint(equalTo:multiplier:constant:)

Returns a constraint that defines the anchor’s size attribute as equal to the specified size attribute multiplied by a constant plus an offset.

```
func constraint(equalTo anchor: NSLayoutDimension, multiplier m: CGFloat, constant c: CGFloat) -> NSLayoutConstraint
```

## Parameters

`anchor`

A dimension anchor from a [`UIView`](/documentation/UIKit/UIView), <doc://com.apple.documentation/documentation/AppKit/NSView>, or [`UILayoutGuide`](/documentation/UIKit/UILayoutGuide) object.

`m`

The multiplier constant for the constraint.

`c`

The offset constant for this relationship.

## Return Value

An [`NSLayoutConstraint`](/documentation/UIKit/NSLayoutConstraint) object that defines the attribute represented by this layout anchor as equal to the attribute represented by the `anchor` parameter multiplied by the `m` constant plus the constant `c`.

## Discussion

This method defines the relationship `first attribute = (m * second attribute) + c`. 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.

The constraints produced by the following two examples are identical.

```swift
// Creating a constraint using NSLayoutConstraint
NSLayoutConstraint(item: button,
                   attribute: .Width,
                   relatedBy: .Equal,
                   toItem: button,
                   attribute: .Height,
                   multiplier: 2.0,
                   constant: 40.0).isActive = true
 
// Creating the same constraint using constraintEqualToAnchor:multiplier:constant:
button.widthAnchor.constraintEqualToAnchor(button.heightAnchor, multiplier: 2.0, constant: 40.0).isActive = true
```

---

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)