In language Cocoa uses to define view constraints, examples are always named “button1”, “button2”, etc. But what do this names actually mean? Are they names of the nub files, the class names of controllers or views? If I instantiate several views of the same nib file and class, what names do they get, and how can I set them?
In language Cocoa uses to define view constraints , examples are always named button1,
Share
They are placeholders that will be associated with actual buttons in your nib file.
Update
If you’re adding constraints in code using
addConstraints:options:metrics:views:method on view you’re trying to constraint (whether that instance ofUIViewwas created in code or loaded from nib), the last parameter (views:) accepts dictionary who’s keys are the ones you provide inUIConstraint‘s ascii art (button1, button2, etc.) and values are actual views that you create in code or get the instances from somewhere else (IBOutlet maybe).You can create the dictionary quickly by using
NSDictionaryOfVariableBindingsmacro which will accept variable number of your instances of views and associate them with same placeholder names like names of those instances. E.g.