lazy var pageControl: UIPageControl = {
let pageControl = UIPageControl()
pageControl.currentPageIndicatorTintColor = FooiyColors.pink
pageControl.pageIndicatorTintColor = FooiyColors.pageIndicator_gray
pageControl.numberOfPages = 6
pageControl.currentPage = 0
pageControl.preferredIndicatorImage = UIImage(named: "pageIndicator_default")
return pageControl
}()
- UIPageViewController 의 delegate 메서드 중 willTransitionTo 와 didFinishAnimating 을 사용한다.
...
var currentIndex: Int?
var pendingIndex: Int?
...
func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
pendingIndex = vcArray.firstIndex(of: pendingViewControllers.first!)
}
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if completed {
currentIndex = pendingIndex
if let index = currentIndex {
pageControl.currentPage = index
}
}
}