Constraint Math

All constraints, regardless of how they are created, are essentially equations or inequalities in the following form:

y (relation) m * x + b

If you have a math background, you may have seen a form more like this, with R referring to the relation between y and the computed value on the right side:

y R m * x + b

y and x are view attributes of the kind you just read about above, such as width or centerY or top. Here, m is a constant scaling factor, and b is a constant offset. For example, you might say, “View B’s left side should be placed 15 points to the right of View A’s right side.” The relation equation that results is something like this:

View B’s left = View A’s right + 15

Here, the relation is equality, the constant offset ...

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.