【问题标题】:Multiple autolayout constraints with same variable value具有相同变量值的多个自动布局约束
【发布时间】:2015-11-12 12:46:31
【问题描述】:

有没有办法从代码(或直接在界面生成器中)设置多个约束的常量,而不必为每个约束创建一个 IBOutlet?

【问题讨论】:

  • 奥特莱斯系列?
  • 这样我就必须遍历集合中的每个约束。有没有办法直接在界面生成器中做? “常数”字段中的“18”表示“一些随机变量”?但也许奥特莱斯系列是最好的选择..
  • 我不认为你可以在 IB / iOS 中那样绑定

标签: ios swift autolayout nslayoutconstraint


【解决方案1】:

你可以这样使用:

for constraint in view.constraints {
    // Identify the constraint using a combination of the following:
    // constraint.identifier ==
    // constraint.firstAttribute ==
    // constraint.firstItem ==
    // constraint.secondAttribute ==
    // constraint.secondItem ==
    // constraint.multiplier ==
    // constraint.constant ==
    if constraint-is-correctly-identified {
        constraint.constant = 42
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 2019-09-29
    相关资源
    最近更新 更多