import UIKit
import PageControl
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var pageControl: PageControl!
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
pageControl.numberOfPages = Int(scrollView.contentSize.width / scrollView.bounds.width)
pageControl.addTarget(self, action: #selector(pageControlDidChangeCurrentPage(_:)), for: .valueChanged)
}
@objc func pageControlDidChangeCurrentPage(_ pageControl: PageControl) {
scrollView.setContentOffset(CGPoint(x: scrollView.bounds.width * CGFloat(pageControl.currentPage), y: 0), animated: true)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.isDragging || scrollView.isDecelerating {
let page = scrollView.contentOffset.x / scrollView.bounds.width
pageControl.setCurrentPage(page)
}
}
}
-
Notifications
You must be signed in to change notification settings - Fork 11
● ○ ○ ○ Animated UIPageControl alternative.
License
kasper-lahti/PageControl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
● ○ ○ ○ Animated UIPageControl alternative.
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published