[英]@IBDesignable class's property not initialized
我有一個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
, foo
為0
,因此XCode中顯示的視圖是錯誤的。 我可以在prepareForInterfaceBuilder()
為foo
賦值來解決此問題。 我不知道是什么引起了這個問題。
您需要將foo標記為@IBInspectable
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.