Search code examples
iosswiftxcodeuiviewxib

Can we update label in xib file for different views?


I'm new to iOS app development. I intend to create an iOS TabBar application:

enter image description here

To do so, I wanted to create a template for the header which is photo. I created a xib file

enter image description here

which contains a label and I would like to use this template in my firstView, secondView and thirdView with different values assigned to that label. Is it possible ?

Swift file for firstView:

enter image description here

Swift file for Header (xib):

enter image description here


Solution

  • You can create a custom view class backing your .xib template, expose the label property of this class to InterfaceBuilder using IBInspectable, and add individually configured instances of this view to your three main views. This way you can do everything (except the definition of the template view) in Interface Builder.

    This problem covers large parts of Xcode and IB, so here are some related tutorials you might find interesting (mainly using the #1 hits on Google):