1

我有一个 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调用foois时0,XCode 中显示的视图是错误的。foo我可以给in赋值prepareForInterfaceBuilder()来解决这个问题。我不知道是什么导致了这个问题。

4

1 回答 1

0

您需要将 foo 标记为@IBInspectable

于 2018-06-05T18:21:15.137 回答