Search code examples
swift2uipageviewcontrolleruipagecontrol

how to set UIPageViewController page control background color


I have a page view controller which displays several images. And it has page control at the bottom created by the following code:func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int { return numOfImages } func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { return currentIndex } The background is black as the image shows, so I just want to know is there any way that I can set its background color to clear color? I know this questions have been asked by others, but none of those answers helped.the problem


Solution

  • I found this code from a youtube tutorial, but I've forgot the link, feel free to tell me the video link so that I can give credits to him...anyway, here is the code:

    override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            for view in self.view.subviews{
                if view is UIScrollView{
                    view.frame =  UIScreen.main.bounds
                } else if view is UIPageControl{
                    view.backgroundColor = .clear
                }
            }
        }
    

    just put this code in the PageViewController file