Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a standalone view in storyboard to use programmatically

I'm trying to create and design a UIView using a storyboard but include it in a UIActionSheet programmatically. This is basically to avoid using CoreGraphics positioning functions with pixels

In old xcode I remember that it was possible to drag a UIView onto the nib without any controllers.

The view obviously has to be connected to the class, so it would have an IBOutlet, but not being added to the self.view

One thing that makes me feel like this should be possible is that if you drag a UIView into the controller black bar in storyboard it pops into place like so:

Snapped in UIView

But its not shown on the screen itself. What is this feature for? Can I somehow open up this view and design it a bit?

like image 964
Yarek T Avatar asked Jan 03 '13 13:01

Yarek T


People also ask

How do I create a custom view in storyboard?

Using a custom view in storyboards Open up your story board and drag a View (colored orange below for visibility) from the Object Library into your view controller. Set the view's custom class to your custom view's class. Create an outlet for the custom view in your view controller.

How does storyboard connect to code?

Xcode connects your storyboard to Swift code by using a combination of the Identity Inspector, IBOutlets and IBActions. On the right side of your addressbar, there is a button you can click to activate the Assistant Editor. The first thing you might notice, is the lack of screen space for each open file.

What is better Xib or storyboard?

Storyboards - this is a visual tool for laying out multiple application views and the transitions between them (segues). XIBs (or NIBs) - each XIB file corresponds to a single view element and can be laid out in the Interface Builder, making it a visual tool as well.


1 Answers

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.

like image 127
eric Avatar answered Sep 30 '22 00:09

eric