Changing UIPageViewController own PageController regarding Color of Dots

前端 未结 3 786
梦毁少年i
梦毁少年i 2021-02-04 00:40

Hey I\'m using a UIPageViewController to control what page I am on and for scrolling. I know it\'s possible to show a Page Controller along with it by simply adding the followin

3条回答
  •  忘掉有多难
    2021-02-04 01:35

    UIPageControl conforms to UIAppearance protocol. The Apple Developper API Reference states about UIAppearance:

    Use the UIAppearance protocol to get the appearance proxy for a class. You can customize the appearance of instances of a class by sending appearance modification messages to the class’s appearance proxy.


    Therefore, using Swift 2.2, you may set UIPageControl's pageIndicatorTintColor and currentPageIndicatorTintColor in a subclass of UINavigationController or in your AppDelegate class (for a more global approach).

    CustomNavigationController.swift:

    class CustomNavigationController: UINavigationController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Set pageIndicatorTintColor and currentPageIndicatorTintColor
            // only for the following stack of UIViewControllers
            let pageControl = UIPageControl.appearance()
            pageControl.pageIndicatorTintColor = UIColor.blueColor()
            pageControl.currentPageIndicatorTintColor = UIColor.greenColor()
        }
    
    }
    

    AppDelegate.Swift:

    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
        func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
            // Set pageIndicatorTintColor and currentPageIndicatorTintColor globally
            let pageControl = UIPageControl.appearance()
            pageControl.pageIndicatorTintColor = UIColor.blueColor()
            pageControl.currentPageIndicatorTintColor = UIColor.greenColor()
    
            return true
        }
    
    }
    

提交回复
热议问题