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

≯℡__Kan透↙ 提交于 2019-12-05 00:53:56

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
}

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
    }

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

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!