Skip to content

ScrollView of image

Mohammad Azmal Hossain edited this page Apr 6, 2017 · 2 revisions

import UIKit

class ViewController: UIViewController {

//instantiating an object of image view.
var imageView: UIImageView!
//instantiating an object of scroll view.
var scrollView: UIScrollView!
//creating an object && assigning an image named "shanks"
var image = UIImage(named: "fullPageImage")

override func viewDidLoad() {
    super.viewDidLoad()
    //setting image to the image view
    imageView = UIImageView(image: image)
    //setting the frame of the scroll view.
    scrollView = UIScrollView(frame: view.bounds)
    //adding imageview as a subview of scroll view
    scrollView.addSubview(imageView)
    // content size of the scroll view is the size of the image
    scrollView.contentSize = imageView.bounds.size
    //scroll view is the subview of main view
    view.addSubview(scrollView)
}

}

Clone this wiki locally