Metrics

When you don’t know a constant’s value (like 120 or 50) a priori, use a metrics dictionary to provide the value. This dictionary is passed as one of the parameters to the constraint creation method. Here is an example of a format string that uses a metric stand-in:

[view1(>=minwidth)]

The minwidth stand-in must map to an NSNumber value in the passed metric dictionary. For more examples of metric use, refer to Recipe 5-2’s constrainSize: method. It demonstrates how to use metrics, using values from an associated dictionary in its constraints.

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.