<!--
{
  "availability" : [
    "macOS: 10.7.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSLayoutConstraint/constraints(withVisualFormat:options:metrics:views:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLayoutConstraint(cm)constraintsWithVisualFormat:options:metrics:views:"
  },
  "title" : "constraints(withVisualFormat:options:metrics:views:)"
}
-->

# constraints(withVisualFormat:options:metrics:views:)

Creates constraints described by an ASCII art-like visual format string.

```
class func constraints(withVisualFormat format: String, options opts: NSLayoutConstraint.FormatOptions = [], metrics: [String : Any]?, views: [String : Any]) -> [NSLayoutConstraint]
```

## Parameters

`format`

The format specification for the constraints.

`opts`

Options describing the attribute and the direction of layout for all objects in the visual format string.

`metrics`

A dictionary of constants that appear in the visual format string. The dictionary’s keys must be the string values used in the visual format string. Their values must be <doc://com.apple.documentation/documentation/Foundation/NSNumber> objects.

`views`

A dictionary of views that appear in the visual format string. The keys must be the string values used in the visual format string, and the values must be the view objects.

## Return Value

An array of constraints that, combined, express the constraints between the provided views and their parent view as described by the visual format string. The constraints are returned in the same order they were specified in the visual format string.

## Discussion

For more information, see [`NSLayoutConstraint`](/documentation/AppKit/NSLayoutConstraint).

## See Also

[`NSLayoutConstraint`](/documentation/AppKit/NSLayoutConstraint)

The relationship between two user interface objects that must be satisfied by the constraint-based layout system.



---

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)