Henry Brown
Henry Brown

Reputation: 2237

How to hide dots on last view of UIPageViewController SWIFT

I want to be able to hide the pagination dots on the last view of a UIPageViewController. There is this question which has already asked it but it is never answered.

If someone could just give me an overview of how this is achievable.

Thanks

EDIT:

func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
        pageControl.hidden = true
        print(pageControl.hidden)//Always is false
    }

Upvotes: 4

Views: 1169

Answers (1)

Eduardo Oliveros
Eduardo Oliveros

Reputation: 857

use the UIPageViewControllerDelegate method:

let pageControl = UIPageControl()

override func viewDidLoad(){
    super.viewDidLoad()
    pageControl.numberOfPages = numberOfPages()
    pageControl.currentPage = 0
    view.addSubview(pageControl)
    pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
    pageControl.pageIndicatorTintColor = UIColor.whiteColor().colorWithAlphaComponent(0.4)
}

func numberOfPages() -> Int {
    return 4 //your number of pages
}

func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
    if (index == numberOfPages()-1){
          pageControl.hidden = true
    }else{
          pageControl.hidden = false
    }
}

too you can migrate to icarousel its very powerful and easily to implement https://www.youtube.com/watch?v=OLvZbXOAZQY

Upvotes: 2

Related Questions