¿Cómo diseñar UIView independiente fuera de cualquier ViewController en Storyboard?

I would like to design a UIView, which is larger than a ViewController in Storyboard (iOS 5).

The UIView should be used as the subview of a UIScrollView and hence be larger than any of my existing ViewControllers. How can I create such a UIView in Storyboard and associate it with my UIScrollView?

I would like to do this without xib files if possible.


preguntado el 10 de marzo de 12 a las 16:03

Tricky problem, this was so easy before the age of storyboards. -

3 Respuestas

I see no other option than using xibs, but it's not that annoying:

//We have file called "View.xib" in our project. It contains one SINGLE view
NSArray *xibContents = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];
UIView *view = [xibContents lastObject]; //safer than objectAtIndex:0

[self.scrollview addSubview:view];
self.scrollview.contentSize = view.frame.size; 

In order to make IB connections you can set the filesOwner class in the xib to be your viewController, and connect like usual.

Respondido 20 Jul 16, 22:07

You may want to have a look at my related question/answer, regarding the design decisions that may justify that: stackoverflow.com/questions/11386111/… - KPM

Clean and super fast solution. Thank you very much. - androniennn

Added stand alone .xib file not working for auto layout. Though whole project is with auto layout. How i apply auto layout with this .xib file? - Shah Nilay

Puedes colocar un UIView into your scrollview and directly design it inside the viewController de tu scrollView

respondido 10 mar '12, 16:03

Hi Ugur, my UIView is larger than the ScrollView, so the majority of controls would be outside the currently visible area. - AlexR

Than xibs may be the only solution to design it in an interface builder - Ugur Kumru

I've found the way to edit the view added to the scene (being at the same hierarchy level as ViewController).

Unfortunately it is from hackish types of actions. My Xcode la versión es Version 4.5.2 (4G2008a). I've tested this in real project and new empty project.

La idea básica es que Xcode do have an ability to edit such external views, unfortunately this mode doesn't activate straightforwardly.

In the method that I've found you need to have 2 levels of hierarchy inside your external view:

|- VC
   |- View
|- ExternalView
   |- SubView1
      |- SubView2
  • Luego ve a Document Outline panel
  • encontrar SubView2 in the tree of your scene
  • double click it

The editing area will appear and its coordinates will be saved to project's user data, so you can move it to more suitable place if you want to, and next time you'll open the storyboard in IB on the machine it will be there. Although I think on other machines you'll have to do it again (I haven't tested that).

Respondido el 07 de diciembre de 12 a las 18:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.