steps for creating UIScrollView with Interface Builder

UPDATE

I have posted another solution here which I think is simpler and better.

ORIGINAL

Here’s another way to do this that you might like better:

  1. Set the File’s Owner placeholder’s custom class to your view controller subclass.
  2. Create the UIScrollView as a top-level object in your nib. Set its size to the screen size (320×460) or just turn on a status bar under “Simulated Metrics”.
  3. Connect the scroll view’s delegate outlet to File’s Owner.
  4. Set the File’s Owner’s view outlet to the scroll view.
  5. Create a UIView as another top-level object in your nib. This will be your content view.
  6. Set the content view’s size to 320×700.
  7. Create a strong (or retain, if not using ARC) outlet named contentView in your view controller (File’s Owner) and connect it to the content view.
  8. Put your buttons in the content view.
  9. In your view controller’s viewDidLoad, do this:

    - (void)viewDidLoad {
        [super viewDidLoad];
        [self.view addSubview:self.contentView];
        ((UIScrollView *)self.view).contentSize = self.contentView.frame.size;
    }
    
  10. In your view controller’s viewDidUnload, do this:

    - (void)viewDidUnload {
        self.contentView = nil;
        [super viewDidUnload];
    }
    

scrollbuttons project window
Full size

Leave a Comment