View-to-View Predicates

Predicates aren’t limited to numeric constants. You can relate a view’s size to another view, for example, to ensure that it’s no bigger than that view in the layout. This example limits View 2’s extent to no bigger than that of View 1, along the axis that the constraint is currently using:

[view2(<=view1)]

You can’t do a lot more with format strings and view-to-view comparisons. If you want to establish more complex relationships, like those between centers, tops, and heights, skip the visual format strings and use the item constraint constructor instead.

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.