Creating Constraints

The NSLayoutConstraint class lets you create constraints in two ways. You can use a rather long method call to constrain one item’s attribute to another, explaining how these attributes relate, or you can apply a rather nifty visual formatting language to specify how items are laid out along vertical and horizontal lines.

This section demonstrates both approaches, allowing you to see what they look like and how they are used. Remember this: Regardless of how you build your constraints, they all produce “y relation mx + b” results. All constraints are members of the NSLayoutConstraint class, no matter how you create them.

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.