Constraining Size
Recipe 5-2’s second method, constrainSize:, fixes a view’s extent to the CGSize you specify. This is a common task when working with constraints. You cannot just set the frame the way you’re used to setting it. And, again, remember that your constraints are requests, not specific layouts. If your constraints are not well formed, your 100-point-wide text field may end up 107 points wide in deployment—or worse.
You can define constraints that request a specific width or height for a given view, but the sizes for the two constraints can’t be known ahead of time. The method is meant for use across a wide variety of views. Therefore, the sizes are passed to the constraint as metrics. Metrics basically act as numeric constraint variables. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access