Search code examples
swiftxcodeuiviewstoryboard

Re-using complex custom UI elements - Xcode Storyboard


In Xcode on the StoryBoard I built a complex UI element consisting of many sub-views.

I encapsulated it all into a UIView subclass but each element has to be built out on the storyboard wherever it is used.

Is there a way to build it in such a way that all a developer would need to do to use it is to add a UIView of the appropriate sub-class and not need to layout all of the subviews? Similar to how we do not need to interact with the underlying structure of buttons or labels.


Solution

  • This is possible, but it requires a bit of a workaround. It basically requires you to create a UIView subclass, which loads all it's subviews from a separate nib file

    This question has the answers for you.