Definition

According to apple, The UIScrollView class provides support for displaying content that is larger than the size of the application’s window. It enables users to scroll within that content by making swiping gestures, and to zoom in and back from portions of the content by making pinching gestures.

To get started, the most important properties of a UIScrollView are:

  1. contentSize
  2. contentInset
  3. contentOffset
  4. delegate

The most important methods to know are:

- (void)scrollRectToVisibleπŸ™CGRect)rect animatedπŸ™BOOL)animated
- (void)setContentOffsetπŸ™CGPoint)contentOffset animatedπŸ™BOOL)animated

Delegates:

- (void)scrollViewDidEndDeceleratingπŸ™UIScrollView *)scrollView
- (void)scrollViewDidEndDraggingπŸ™UIScrollView *)scrollView
willDecelerateπŸ™BOOL)decelerate
- (void)scrollViewWillBeginDeceleratingπŸ™UIScrollView *)scrollView
- (void)scrollViewWillBeginDraggingπŸ™UIScrollView *)scrollView
Now open the XCode, create a new project and drag & drop a UIScrollView in the ViewController on the storyboard.
scrollview1

Now we need to open the Assistant Editor, your screen should be like this:
scrollview2
Right click on the ScrollView and Drag it to the Code editor and release, to insert the outlet, and give the outlet a name
scrollview3“scrollView” and press enter. Now we have an outlet of UIScrollView.
Now we need to open the ViewController.m file and insert the UIScrollView delegate functions:

-(UIView *)viewForZoomingInScrollViewπŸ™UIScrollView *)scrollView{
    return imgView;
}
-(void)scrollViewDidEndDeceleratingπŸ™UIScrollView *)scrollView{
    NSLog(@"Did end decelerating");
}	
-(void)scrollViewDidScrollπŸ™UIScrollView *)scrollView{
//    NSLog(@"Did scroll");
}
-(void)scrollViewDidEndDraggingπŸ™UIScrollView *)scrollView 
  willDecelerateπŸ™BOOL)decelerate{
    NSLog(@"Did end dragging");
}
-(void)scrollViewWillBeginDeceleratingπŸ™UIScrollView *)scrollView{
    NSLog(@"Did begin decelerating");
}
-(void)scrollViewWillBeginDraggingπŸ™UIScrollView *)scrollView{
    NSLog(@"Did begin dragging");
}

This is how we implement a UIScrollView using storyboards.
Some of the developers do not like to use storyboard builders so we can implement a UIScrollView from the code.
We open the ViewController.h file and we modify the file to have this:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIScrollViewDelegate>
{
    UIScrollView *scrollView;
}	

@end

Now we open the ViewController.m file and create a method (function) to create the UIScrollView and add it to our view controller.

-(void)createScrollView{
    scrollView = [[UIScrollView alloc]initWithFrame:
    CGRectMake(20, 20, 280, 420)];
    scrollView.accessibilityActivationPoint = CGPointMake(100, 100);
    imgView = [[UIImageView alloc]initWithImage:
    [UIImage imageNamed:@"anyImage.jpg"]];
    [scrollView addSubview:imgView];
    scrollView.minimumZoomScale = 0.5;
    scrollView.maximumZoomScale = 3;
    scrollView.contentSize = CGSizeMake(imgView.frame.size.width,
    imgView.frame.size.height);
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
}

We use the same delegate methods as before. But no we modify the ViewDidLoad method and call our createScrollView method as follow:

(void)viewDidLoad
{
   [super viewDidLoad];
   [self createScrollView];
   //Do any additional setup after loading the view, typically from a nib
}

Run the app using the play button or by using CMD+R from the keyboard.