【问题标题】:@IBDesignable class's property not initialized@IBDesignable 类的属性未初始化
【发布时间】:2015-12-14 09:14:29
【问题描述】:

我有一个 IBDesignable 类。

@IBDesignable
class Foobar: UIView {

    // ignore all init code

    var foo: CGFloat = 12

    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
         // use property foo to draw something
    }

}

让我奇怪的是,当drawRect调用时,foo0,所以XCode中显示的视图是错误的。我可以在prepareForInterfaceBuilder() 中为foo 赋值来解决这个问题。我不知道是什么导致了这个问题。

【问题讨论】:

    标签: swift ibdesignable


    【解决方案1】:

    你需要将 foo 标记为@IBInspectable

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 2017-09-29
      • 2019-12-02
      • 2021-06-21
      • 2017-03-03
      • 2012-05-26
      • 1970-01-01
      相关资源
      最近更新 更多