如何获得约束"bottomSpace"?从UIView以编程方式? [英] How to get constraint "bottomSpace" from UIView Programmatically?

查看:56
本文介绍了如何获得约束"bottomSpace"?从UIView以编程方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式更改某些视图的中心.10以上.我不想将每个底部约束都添加为出口,所以我可以从如下代码中搜索它们:

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)

我应该检查哪些属性?我需要约束Superview的底部空间.

Which attributes should I check? I need constraint for bottom space of superview.

推荐答案

您是否听说过 IBOutletCollection ?当您将任何对象从IB链接到VC代码时,在弹出窗口中,您可以选择IBOutletCollection Option.链接完所需的所有约束后,只需迭代此集合即可:)

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
}

这篇关于如何获得约束"bottomSpace"?从UIView以编程方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆