I have a custom view class that is supposed to just contain a label. I have an extension in each target that will provide the text that should be displayed in the view, this way I don't have recreate each controller just to have a different label and background color in it.
My custom code is:
@IBDesignable
class HomeAccentView: UIView {
@IBOutlet weak var nameLabel: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
override func awakeFromNib() {
super.awakeFromNib()
setup()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setup()
}
private func setup() {
backgroundColor = UIColor.main
nameLabel.text = String.headerText
nameLabel.textColor = UIColor.white
}
}
I have my nib's file owner as HomeAccentView and the label is connected as an outlet on the storyboard.
But whenever I try to set the text of the label it's always nil. What am I missing or doing wrong?