How to put the UIPageControl element on top of the sliding pages within a UIPageViewController?

后端 未结 7 1695
闹比i
闹比i 2020-12-02 10:20

Regarding to this tutorial by AppCoda about how to implement a app with UIPageViewController I\'d like to use a custom page control element on top of the pages instead of at

相关标签:
7条回答
  • 2020-12-02 11:12

    After further investigation and searching I found a solution, also on stackoverflow.

    The key is the following message to send to a custom UIPageControl element:

    [self.view bringSubviewToFront:self.pageControl];
    

    The AppCoda tutorial is the foundation for this solution:

    Add a UIPageControl element on top of the RootViewController - the view controller with the arrow.

    Create a related IBOutlet element in your ViewController.m.

    In the viewDidLoad method you should then add the following code as the last method you call after adding all subviews.

    [self.view bringSubviewToFront:self.pageControl];
    

    To assign the current page based on the pageIndex of the current content view you can add the following to the UIPageViewControllerDataSource methods:

    - (UIPageViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
    {
        // ...
        index--;
        [self.pageControl setCurrentPage:index];
    
        return [self viewControllerAtIndex:index];
    }
    
    - (UIPageViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
    {
        // ...
        index++;
        [self.pageControl setCurrentPage:index];
    
        // ...
        return [self viewControllerAtIndex:index];
    }
    
    0 讨论(0)
提交回复
热议问题