Swift/iOS8: Why are Page Control indicators not showing?

后端 未结 6 2337
暗喜
暗喜 2021-02-19 08:54

I am implementing a straightforward gallery view controller where the app displays a small range of full-screen images that the user can scroll through. I\'m using UIPageViewCon

相关标签:
6条回答
  • 2021-02-19 09:00

    Even if you will change color of UIPageControl it may not appear. If UIPageController is inside the UITabBarController the TabBar will cover the UIPageControl. The best way to find it is use option Debug->View Debubging->CaptureViewHierarchy. Then in the left bottom filter field type "pageControl". If you click it in the navigator it should locate it on the screen (take a look at the screenshot)

    You can change the position like this:

    let controlHeight: CGFloat = 50
        let bottomSpace: CGFloat = 20
        let yPosition = view.frame.size.height - (controlHeight + bottomSpace)
        let fullScreenWidth = view.frame.size.width
        let frame = CGRect(x: 0, y: yPosition, width: fullScreenWidth, height: controlHeight)
    
        pageControl.frame = frame
    
    0 讨论(0)
  • 2021-02-19 09:01

    Although the answer appears in abundance in many of these answers, I just want to make it explicitly clear that you need to set the UIPageViewController to 'Scroll' before these methods will get hit.

    0 讨论(0)
  • 2021-02-19 09:01

    My mistake was to set the count value more than the actual content pages in my page view controller in presentationCount() delegate method.

    0 讨论(0)
  • 2021-02-19 09:09

    Why not use swift 3+ version of Zell B.'s answer

        func presentationCount(for pageViewController: UIPageViewController) -> Int {
            return self.providerItemList?.providerItems?.count ?? 0
        }
    
        func presentationIndex(for pageViewController: UIPageViewController) -> Int {
            return 0
        }
    
    0 讨论(0)
  • 2021-02-19 09:17

    Taken from here :

    In order to show UIPageControl, you need to implement two optional datasource methods. Just return the whole number of pages for presentationCountForPageViewController and the initially selected index for presentationIndexForPageViewController

    func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
        return pageContent.count
    }
    
    func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
        return 0
    }
    
    0 讨论(0)
  • 2021-02-19 09:25

    The dots are white, or semitransparent white. Make sure the background is not white, or change the colour of the dots.

    0 讨论(0)
提交回复
热议问题