StoryboardXibController is a utility class made to separate complex view controllers and view data out of your storyboard and into your Xibs, all within Xcode's Interface Builder.
Using this class you can easily load an Xib from within a storyboard at runtime. Currently this is restricted to Xib files whose File's Owner is a UIViewController
or UIViewController
subclass.
StoryboardXibController is available through cocoapods, to install simple add the following line to your PodFile
:
pod "StoryboardXibController"
Alternatively you can clone the github repo.
Once you've installed the class:
-
Add a new view controller scene to your storyboard.
-
Find the Custom Class property within the view controller's Identity Inspector tab
-
Change the view controller's Custom Class from
UIViewController
toStoryboardXibController
.
In Xcode 6:
-
Find the Screen Controller property within the view controller's Attributes Inspector tab
-
Change the view controller's Screen Controller to the name of the class of your
Xib
's File's Owner/main view controller. -
Find the Screen Nib property immediately below
-
Change the view controller's Screen Nib property to the name of the
Xib
file you wish to load.
In Xcode 5 and below:
-
Find the User Defined Runtime Attributes within the same Identity Inspector tab
-
Add an attribute with the Key Path
screenControllerClass
of TypeString
with the Value of the name of the class of yourXib
's File's Owner/main view controller.
- Add a second attribute with the Key Path
screenNib
of TypeString
with theValue
of the name of theXib
file you wish to load.
- Enjoy!
- To align the contained view with the Top Layout Guide or Bottom Layout Guide toggle the two view controller properties:
Align To Top Layout Guide
Align To Bottom Layout Guide
- Or if you're pre-Xcode6 add attributes of
BOOL
value with the Key Paths:alignToTopLayoutGuide
alignToBottomLayoutGuide
Thanks to @fatuhoku for the idea and assistance in developing the feature.
If you have any ideas, suggestions or bugs to report please create an issue labeled feature or bug (check to see if the issue exists first please!). Or suggest a pull request!