Basic Constraint Declarations

The NSLayoutConstraint’s class method constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant: (gesundheit!) creates a single constraint at a time. These constraints relate one item to another.

The creation method produces a strict view.attribute R view.attribute * multiplier + constant relation, where R is an equal-to (==), a greater-than-or-equal-to (>=), or a less-than-or-equal-to (<=) relation.

Consider the following example:

[self.view addConstraint:     [NSLayoutConstraint         constraintWithItem:textfield         attribute:NSLayoutAttributeCenterX         relatedBy:NSLayoutRelationEqual         toItem:self.view         attribute:NSLayoutAttributeCenterX ...

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.