Skip to content

Instantly share code, notes, and snippets.

@hellyeah
Created October 25, 2015 22:33
Show Gist options
  • Save hellyeah/30417826a2488705a671 to your computer and use it in GitHub Desktop.
Save hellyeah/30417826a2488705a671 to your computer and use it in GitHub Desktop.
class ScrollViewController: UIViewController, UIScrollViewDelegate {
var scrollView: UIScrollView!
var imageView: UIImageView!
var pageControl: UIPageControl!
override func viewDidLoad() {
super.viewDidLoad()
scrollView = UIScrollView(frame: view.bounds)
let contentWidth = scrollView.bounds.width
let contentHeight = scrollView.bounds.height * 3
scrollView.contentSize = CGSizeMake(contentWidth, contentHeight)
view.addSubview(scrollView)
let pageWidth = scrollView.bounds.width
let pageHeight = scrollView.bounds.height
scrollView.contentSize = CGSizeMake(3*pageWidth, pageHeight)
scrollView.pagingEnabled = true
scrollView.showsHorizontalScrollIndicator = false
let view1 = UIView(frame: CGRectMake(0, 0, pageWidth, pageHeight))
view1.backgroundColor = UIColor.blueColor()
let view2 = UIView(frame: CGRectMake(pageWidth, 0, pageWidth, pageHeight))
view2.backgroundColor = UIColor.orangeColor()
let view3 = UIView(frame: CGRectMake(2*pageWidth, 0, pageWidth, pageHeight))
view3.backgroundColor = UIColor.purpleColor()
scrollView.addSubview(view1)
scrollView.addSubview(view2)
scrollView.addSubview(view3)
scrollView.delegate = self
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment