Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting static content in a UIScrollView through XIB

I need a UIScrollview to show some static content in my app. I have taken a UIScrollView through XIB and started adding some UIImageViews and textViews in to it. But after coming to the end of the scrollView the view is not exapanding anymore. I need more space so that I can add some more views below. Is there any way in which I can do this (through XIB and not through code).

like image 522
A for Alpha Avatar asked Mar 13 '11 14:03

A for Alpha


1 Answers

I struggled a lot to get this done in a more elegant way then the solution described by Csabi. It's really simple:

  1. In your xib file just add a generic view which is not a subview of your viewController.view (i.e although this view is in your xib file, it is not a part of your viewController's view hierarchy.)

  2. Then select this view and using size inspector set the width and height that suits your need. Add whatever objects you want to this view. Hook up this view to your viewController with an IBOutlet. (Let's call it IBOutlet UIView *myBigView).

  3. in your viewController.view drag a ScrollView and adjust the size of the scroll view as you like. Hook this up to your viewController. (IBOutlet UIScrollView *scrollView)

  4. Now it's super simple:

    -(void) viewDidLoad{
        [super viewDidLoad];    
        self.scrollView.contentSize = self.myBigView.bounds.size;
        [self.scrollView addSubview:self.myBigView]; 
    }
    
like image 156
Raunak Avatar answered Oct 06 '22 01:10

Raunak