How to get constraint “bottomSpace” from UIView Programmatically?

只愿长相守 提交于 2021-01-27 21:17:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!