UIPageControl
符合UIAppearance
协议。Apple 开发人员 API 参考说明UIAppearance
:
使用UIAppearance
协议获取类的外观代理。您可以通过向类的外观代理发送外观修改消息来自定义类实例的外观。
因此,使用 Swift 2.2,您可以在类的子类或类中设置UIPageControl
'spageIndicatorTintColor
和(用于更全局的方法)。currentPageIndicatorTintColor
UINavigationController
AppDelegate
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
}
}