问题
I need change center of some views programmatically. 10 or more. I don't want to adding each bottom constraint as outlet, so could I search them from code like as:
for(NSLayoutConstraint *constraint in view.constraints)
Which attributes should I check? I need constraint for bottom space of superview.
回答1:
Have you heard about IBOutletCollection
? When you link any object from IB to VC code, in popup window you can select IBOutletCollection Option. After link all constraints you want, only iterate this collection :)
@property (strong, nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray *contentViewConstraints;
for (int i = 0; i < contentViewConstraints.count; i++) {
NSLayoutConstraint *constraint = contentViewConstraints[i];
//Center here
}
来源:https://stackoverflow.com/questions/29348661/how-to-get-constraint-bottomspace-from-uiview-programmatically