Search code examples
iosswiftxibiboutlet

iOS: Inheritance with different xib files


UIViewA is defined in .xib and .swift. I would like to create a UIView with it own .xib that inherits from UIViewA with several extra properties.

So:

class UIViewA: UIView {
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var subtitleLabel: UILabel!
}

class UIViewB: UIViewA {
    @IBOutlet weak var thirdLabel: UILabel!
}

Both UIViewA and UIViewB have titleLabel and subtitleLabel. They are just positioned differently in there xibs. Is there a way I could drag titleLabel in UIVIewB.xib to the titleLabel IBOutlet in UIViewA.swift?


Solution

  • Yes, you can do it. In your example, if you open UIVIewB.xib and the file owner is the class UIVIewB you can open another editor window with the class UIViewA and you can drag the UI elements to the UIViewA properties.

    Like this: enter image description here