Create a standalone view in storyboard to use programmatically Create a standalone view in storyboard to use programmatically xcode xcode

Create a standalone view in storyboard to use programmatically


Just create a new .xib file.

  1. Right Click somewhere in the Navigator Area and select 'New File...'.
  2. Select 'User Interface' from the list on the right and Select 'View'.
  3. Click 'Next', 'Next', give your new view a name, and 'Create'.
  4. A new .xib fill will be added to your project.
  5. Double clicking on the new .xib file and it opens in Interface Builder (not Storyboard).
  6. Edit/Design your View to your liking.

Then after you have your new view (.xib) in Interface Builder, it's a simple matter of creating a new subclass of UIView (ex. MyView), switching the class of your new view (.xib) to MyView, creating an instance of MyView in your controller, and adding it as a subview to your other view.


*And to answer your question about that little black bar at the bottom, it's called the 'Dock', and it's just a mini representation of the top-level documents of your scene. The dock is convenient for quickly dragging/dropping icons onto and making connections. See apple's storyboard description here. Ray Wenderlich has an easy to follow tutorial on storyboards here.


You cannot have a UIView outside of a UIViewController on a storyboard. I'm guessing it's because the storyboard would have no idea how to identify or instantiate with the current API. It is something I've had a use for myself. The solution is just use a XIB for the one UIView and load it up programmatically (just like used to do). I've found using a storyboard for most items and couple XIBs for re-usable views across multiple view controllers do work nicely together.

Here is some code I use to load a XIB as part of a custom object with the object gets initialized.

- (id)initWithFrame:(CGRect)frame {    self = [super initWithFrame:frame];    if (self) {        // Initialization code        [[[NSBundle mainBundle] loadNibNamed:@"BannerView" owner:self options:nil] objectAtIndex:0];        [self addSubview:self.view];        self.frame = self.view.frame;    }    return self;}

As for dragging views down into the black bar on the storyboards. Those views are still part of the UIViewController, but they aren't a `subview' of the top level view. I think the document outline shows the hierarchy nicely.

The following view has 2.1.1 View, 2.1.2 View, etc outside of my main view hierarchy because they aren't subviews of my main view. The result is, they won't be displayed by default. I do have IBOutlets setup and I conditionally add/remove them from my main view hierarchy using the standard addSubview: and removeFromSuperview.

IB Document Outline example