Reputation: 2557
I'm trying this IBDesignable. But as always it don't work.
My controller code:
@IBDesignable
class MainMenuViewController: UIViewController {
@IBOutlet weak var languagesButton: UIView!
@IBOutlet weak var keyboardSettingsButton: UIView!
@IBOutlet weak var aboutButton: UIView!
@IBOutlet weak var helpButton: UIView!
@IBInspectable var buttonsCornerRadius: CGFloat = 5 {
didSet {
languagesButton.layer.cornerRadius = buttonsCornerRadius
keyboardSettingsButton.layer.cornerRadius = buttonsCornerRadius
aboutButton.layer.cornerRadius = buttonsCornerRadius
helpButton.layer.cornerRadius = buttonsCornerRadius
}
}
override func prepareForInterfaceBuilder() {
languagesButton.layer.cornerRadius = buttonsCornerRadius
keyboardSettingsButton.layer.cornerRadius = buttonsCornerRadius
aboutButton.layer.cornerRadius = buttonsCornerRadius
helpButton.layer.cornerRadius = buttonsCornerRadius
}
}
I have this property in my interface builder:
But it never update my storyboard. And when I run my application it just crash with no message.
Upvotes: 3
Views: 1558
Reputation: 4277
As I said in my comment, all your IBOutlets are nil on this stage. You have an "unexpectedly found nil while unwrapping an Optional value"
What I can suggest is to make a custom class of UIView
and then inside this class, you can add a property "cornerRadius" as @IBInspectable
like this :
import UIKit
@IBDesignable
class MyCustomView:UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
}
Using this approach and every time you change the value in IB, your view will be updated.
Upvotes: 3