根据:
的:
UINavigationBar.appearance().backgroundColor = UIColor.greenColor() UIBarButtonItem.appearance().tintColor = UIColor.magentaColor() UINavigationBar.appearance().titleTextAttributes = [UITextAttributeTextColor: UIColor.blueColor()] UITabBar.appearance().backgroundColor = UIColor.yellowColor();
参考:
得知:
- UINavigationBar
- UIBarButtonItem
- UINavigationBar
- UITabBar
都实现了UIAppearance这个协议
-》所以这些类,控件才有appearance()
-》然后可以通过这些类的appearance()去全局地设置各种颜色:背景色,文字图片的颜色等等
-》
官网的解释中都用此来举例了“For example, to modify the bar background tint color for all instances of
UINavigationBar
:”