【问题标题】:Is there a way to make a custom constraint work in interface builder?有没有办法让自定义约束在界面生成器中工作?
【发布时间】:2019-12-13 09:01:12
【问题描述】:

制作一个具有固定高度约束的 UIView,注意我在 IB 中将其设置为 40。

将约束类改成这样:

@IBDesignable class BadassHeightConstraint: NSLayoutConstraint {

    override var constant: CGFloat {
        set {
            super.constant = newValue
        }
        get {
            return calc()
        }
    }

    private func calc() -> CGFloat {
        return 100.0
    }
}

在运行时完美运行,左图是 100,而不是 40。

但是,我无法让它在 IB 中工作。为什么会这样?

有什么解决方案可以在 IB 中进行这些工作吗?

【问题讨论】:

    标签: ios interface-builder nslayoutconstraint ibdesignable


    【解决方案1】:

    简单来说,只有一个 UIView 可以是@IBDesignable

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-30
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 2015-02-05
      相关资源
      最近更新 更多