Visual Format Language

This appendix shows how to use the Auto Layout visual format language to specify common constraints, including standard spacing and dimensions, vertical layout, and constraints with different priorities. In addition, this appendix contains a complete language grammar.

Visual Format Syntax

The following are examples of constraints you can specify using the visual format. Note how the text visually matches the image.

Standard Space


Width Constraint


Connection to Superview


Vertical Layout


Flush Views




Equal Widths


Multiple Predicates


A Complete Line of Layout



The notation prefers good visualization over completeness of expressibility. Most of the constraints that are useful in real user interfaces can be expressed using visual format syntax, but there are a few that cannot. One useful constraint that cannot be expressed is a fixed aspect ratio (for example, imageView.width = 2 * imageView.height). To create such a constraint, you must use constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:.

Visual Format String Grammar

The visual format string grammar is defined as follows (literals are shown in code font; e denotes the empty string).


Replacement rule

























<constant>|<viewName> (see note)






Parsed as a C identifier.

This must be a key mapping to an instance of NSView in the passed views dictionary.


Parsed as a C identifier. This must be a key mapping to an instance of NSNumber in the passed metrics dictionary.


As parsed by strtod_l, with the C locale.

If you make a syntactic mistake, an exception is thrown with a diagnostic message. For example:

Expected ':' after 'V' to specify vertical arrangement
A predicate on a view's thickness must end with ')' and the view must end with ']'
Unable to find view with name blackBox
Unknown relation. Must be ==, >=, or <=