April 2015
Intermediate to advanced
556 pages
17h 47m
English
You have seen how constraints can be created in Interface Builder, but they can also be added programmatically using the NSLayoutConstraint class. Above, you created the constraint pinning the left side of the scroll view the standard distance from the left side of its superview, the window’s content view, using the Add New Constraints popover in IB. You would create an equivalent constraint programmatically like this:
let scrollView: NSScrollView = ... let superview = scrollView.superview! let constraint = NSLayoutConstraint(item: scrollView, attribute: .Leading, relatedBy: .Equal, toItem: superview, attribute: .Leading, multiplier: 1.0, constant: 20.0) superview.addConstraint(constraint) ...
Read now
Unlock full access