Code for create UIScrollView (which named scrollView) and specify size of content (width and height) inside scrollView.
var scrollView = UIScrollView(frame: containerView.frame)
scrollView.contentSize = CGSize(width: 3000, height: 2000)
containerView.addSubview(scrollView)
// can be any view that is container of scrollView
Use these following code if you need to catch event while scroll and zoom scrollView.
[don’t forget to add delegate]
UIScrollViewDelegate
// add at top of class
scrollView.delegate = self
// add at viewDidLoad()
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? { return imageView }
// return any view that you want to zoom in or out
func scrollViewDidZoom(scrollView: UIScrollView) { /* code for do something while zooming scrollView */ }
func scrollViewDidScroll(scrollView: UIScrollView) { /* code for do something while scrolling scrollView */ }
Leave a comment