Skip to content

ScrollView in ViewController

Mohammad Azmal Hossain edited this page Sep 24, 2017 · 1 revision

import Foundation import UIKit

class ScrollViewController: UIViewController, UIScrollViewDelegate {

// class ScrollViewController: UIViewController, UIScrollViewDelegate{

override func viewDidLoad() {
    super.viewDidLoad()
    
    view.backgroundColor = UIColor(red:0.93, green:0.93, blue:0.93, alpha:1.0)
    
    
    
   
    // main Size
        let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.bounds.size.width, height: view.bounds.size.height))
        scrollView.backgroundColor = UIColor.green
        scrollView.isScrollEnabled = true
        scrollView.isPagingEnabled = true
        scrollView.showsVerticalScrollIndicator = true
        //scrollView.showsHorizontalScrollIndicator = true

    // extent size
    scrollView.contentSize = CGSize(width: self.view.bounds.size.width, height: self.view.bounds.size.height * 3)
    
        view.addSubview(scrollView)
        

    
    let view1 = UIView()
    view1.frame = CGRect(x: 10, y: 80, width: 60, height: 60)
        view1.backgroundColor = UIColor.blue
        scrollView.addSubview(view1)
    

    
    let view2 = UIView()
    view2.frame = CGRect(x: 80, y: 1000, width: 100, height: 100)
   
    view2.backgroundColor = .yellow
    
    scrollView.addSubview(view2)
    
    
}

}

Clone this wiki locally