gpt4 book ai didi

swift - @IBDesignable 类的属性未初始化

转载 作者:行者123 更新时间:2023-11-28 08:50:45 25 4
gpt4 key购买 nike

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

最佳答案

你需要将 foo 标记为 @IBInspectable

关于swift - @IBDesignable 类的属性未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34263214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com