7

I am using a page view controller in an iOs app. How do I remove the dots from this controller?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dontShowChecked = NO;
    self.imagesArray = @[  ..];

    self.textsArray = @[ ........
                        ];


    // Create page view controller
    self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WTPageController"];
    self.pageViewController.dataSource = self;

    WTDetailViewController *startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

    // Change the size of page view controller
    CGFloat delta = [[PSDeviceInfo sharedInstance] is_iPhone] ? 50. : 50;

    self.pageViewController.view.frame = CGRectMake(0, 40., self.view.frame.size.width, self.view.frame.size.height - delta);
    [self.view addSubview:_pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];
}

The dots seem to add themselves automatically and are interfering with other UI elements in that area. How do i Remove them completely?

user1028028
  • 6,323
  • 9
  • 34
  • 59
  • Possible duplicate of [Hide dots from UIPageViewController](http://stackoverflow.com/questions/20748897/hide-dots-from-uipageviewcontroller) – ricardopereira Jun 30 '16 at 09:19

4 Answers4

43

The dots are added once your UIPageViewController datasource implements the following methods:

presentationCountForPageViewController:
presentationIndexForPageViewController:

Avoid to implement those to get rid of the UIPageControl dots.

Cornelius
  • 4,214
  • 3
  • 36
  • 55
3

When pages can be increased or decreased dynamically.

So I used below method which will manually hide the component itself.

func togglePageControl(pageCount: Int, threshold: Int = 1) {

    var hidden = true

    if pageCount > threshold {

        hidden = false

    }

    for subView in self.view.subviews {
        if subView is UIScrollView {
            subView.frame = self.view.bounds
        } else if subView is UIPageControl {
            subView.isHidden = hidden
        }
    }
}

And this should be called from

 public func presentationCount(for pageViewController: UIPageViewController) -> Int {

     togglePageControl(pageCount: pages.count)

     // or togglePageControl(pageCount: pages.count, threshold: 5)

     return pages.count
 }
Muhammed Basil
  • 1,834
  • 1
  • 21
  • 39
2

The page control is only displayed if the datasource implements these methods:

presentationCount:
presentationIndex:
0

As long as you implement UIPageViewControllerDataSource functions of presentationCount and presentationIndex it will appear automatically, but in my case they came from server so I didn't know how many there will be and I only wanted to hide them if it is one.

So just return zero on presentationCount and you are golden.