Reputation: 1179
this is my code
@IBDesignable class BarPopView: UIView {
@IBInspectable var ft: NSString = "1"
@IBInspectable var ffPrompt: NSString = "Area"
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupView()
}
func setupView() {
print("text: \(ft), prompt: \(ffPrompt)")
}
}
and i set these value in interface builder
ft: 50
ffPrompt: "Change"
but result is print
"text: 1, prompt: Area"
Upvotes: 0
Views: 924
Reputation: 567
If u want the
func setupView()
to execute after all the var setting complete, Then call the method in viewDidLoad() of the ViewController class, where you will be using your custom view
BarPopView
Upvotes: 2
Reputation: 3647
Its because the method setupView
is called during initialisation and during that the properties have initial values.
If you want to tweak them accordingly , use property observers:
@IBInspectable var ft: String = ""{
didSet {
setupView()
}
}
Upvotes: 3