UIPageViewController page control background color

后端 未结 9 1349
一个人的身影
一个人的身影 2020-12-13 00:23

i\'m using UIPageViewController in my app and it\'s working fine. however, it\'s page control which has been added automatically has a black background which is hiding the c

9条回答
  •  半阙折子戏
    2020-12-13 00:39

    See my setup method's code in which I change page view controller's page control color and it's worked for me.

    private func setupPageController() {
    
        self.pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
        self.pageController?.dataSource = self
        self.pageController?.delegate = self
        self.pageController?.view.backgroundColor = .clear
        self.pageController?.view.frame = CGRect(x: 0,y: 0,width: self.view.frame.width,height: self.view.frame.height)
        self.addChild(self.pageController!)
        self.view.addSubview(self.pageController!.view)
    
        for item in self.pageController?.view?.subviews ?? []{
            if item is UIPageControl{
                (item as! UIPageControl).pageIndicatorTintColor = #colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1)
                (item as! UIPageControl).currentPageIndicatorTintColor = #colorLiteral(red: 1, green: 0.7489039302, blue: 0, alpha: 1)
                break
            }
        }
        let initialVC = strBoard.instantiateViewController(withIdentifier: "TutorialOneVC")
    
        self.pageController?.setViewControllers([initialVC], direction: .forward, animated: true, completion: nil)
    
        self.pageController?.didMove(toParent: self)
    }
    

提交回复
热议问题