How to Present Content Larger Than a Single Screen Efficiently Using iOS Scroll View

In iPhone app development, the iOS scroll view is generally used to view content that can’t fit entirely in a single screen. This UIScrollView is one of the most useful and versatile control. A common iOS control that we recently looked – iOS Table View – is a subclass of iOS Scroll View which provide a great way to display content that is larger to fit into a single screen.

In today’s iOS app tutorial, we’ll build a sample app to demonstrate how to use iOS scroll view control for iPhone app development to display content larger than a single screen efficiently.

Let’s Get Started

Create a new project under file menu.


Select Single View Application.


Enter the project details and click on Next.


Once you successfully create a new project, go to Main.Storyboard and select ViewController.


Now drag and drop UIScrollView from “Show the object library” section.



Set the outlet of Scroll View in ViewController.swift

@IBOutlet weak var scrMain: UIScrollView!


Now set delegate of ScrollView.


Set auto layout to tableview.


Now define a UIImageView object and add image in UIScrollView.

var imgView: UIImageView!

override func viewDidLoad() {

imgView = UIImageView(image: UIImage(named:"beautiful_swan_2-t2.jpeg")) =
imgView.contentMode = .ScaleAspectFit
imgView.frame = CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height)

scrMain.backgroundColor = UIColor.blackColor()
scrMain.autoresizingMask = [UIViewAutoresizing.FlexibleWidth , UIViewAutoresizing.FlexibleHeight]
scrMain.delegate = self
scrMain.minimumZoomScale = 0.1
scrMain.maximumZoomScale = 4.0
scrMain.zoomScale = 1.0

// Do any additional setup after loading the view, typically from a nib.

Now add delegate method of ScrollView for zoom in/out image in scrollview.

//MARK: ScrollView Delegate
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return imgView

func scrollViewDidZoom(scrollView: UIScrollView) {
let imageViewSize = imgView.frame.size
let scrollViewSize = scrollView.bounds.size

let verticalPadding = imageViewSize.height < scrollViewSize.height ? (scrollViewSize.height - imageViewSize.height) / 2 : 0
let horizontalPadding = imageViewSize.width < scrollViewSize.width ? (scrollViewSize.width - imageViewSize.width) / 2 : 0

scrollView.contentInset = UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)

And done!

When you run the demo, the output should be like this:


So now that you know the implementation process, you’re ready to add iOS scroll view control in your iOS app. And if you’ve face any issue, or can’t seem to implement scroll view control successfully, consult with an expert developer or hire iPhone app developer to do the job for you.

Grab a free copy of ScrollView Demo from Github.

This page was last edited on July 6th, 2018, at 4:27.

Have an iOS App Idea in Mind? Let's Discuss!

Get your free consultation now