Search code examples
objective-ciosios5uiviewuiscrollview

How to design separate UIView outside of any ViewController in 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.

Thank you!


Solution

  • 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.