Cocoa Programming for OS X: The Big Nerd Ranch Guide
by Aaron Hillegass, Adam Preble, Nate Chandler
Challenge: Add Constraints Programmatically
In this chapter, you added constraints to RaiseMan using Interface Builder. Using the NSLayoutConstraint class, add the same constraints, except for those inside the table view. First, do this using the init(item:attribute:relatedBy:toItem:attribute:multiplier:constant:) API. Second, do it again using the constraintsWithVisualFormat(_:options:metrics:views:) API.
You will need to make sure that the constraints you are adding programmatically do not just duplicate the constraints you already added in Interface Builder. However, removing all constraints from IB will not work, because Interface Builder will detect an ambiguous layout and add constraints to prevent it. Instead, select each of ...
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