Reputation: 6433
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?
Upvotes: 7
Views: 12354
Reputation: 534
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.
Upvotes: 0
Reputation: 1082
The page control is only displayed if the datasource implements these methods:
presentationCount:
presentationIndex:
Upvotes: 2
Reputation: 1834
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
}
Upvotes: 3
Reputation: 4264
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.
Upvotes: 43