@IBDesignable类的属性未初始化

时间:2015-12-14 09:14:29

标签: swift ibdesignable

我有一个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中显示的视图是错误的。我可以在foo中为prepareForInterfaceBuilder()分配值来解决此问题。我不知道是什么导致了这个问题。

1 个答案:

答案 0 :(得分:0)

您需要将foo标记为@IBInspectable