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

后端 未结 7 1781
闹比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 10:54

    I didn't have the rep to comment on the answer that originated this, but I really like it. I improved the code and converted it to swift for the below subclass of UIPageViewController:

    class UIPageViewControllerWithOverlayIndicator: UIPageViewController {
        override func viewDidLayoutSubviews() {
            for subView in self.view.subviews as! [UIView] {
                if subView is UIScrollView {
                    subView.frame = self.view.bounds
                } else if subView is UIPageControl {
                    self.view.bringSubviewToFront(subView)
                }
            }
            super.viewDidLayoutSubviews()
        }
    }
    

    Clean and it works well. No need to maintain anything, just make your page view controller an instance of this class in storyboard, or make your custom page view controller class inherit from this class instead.

提交回复
热议问题