2013-10-25 29 views
10

我想改变iOS 7中后退按钮的颜色。现在有没有办法将整个应用程序中的所有导航项更改为特定颜色?这就是我在一个视图控制器截至目前:在整个应用程序中更改导航项目的颜色?

self.editButtonItem.tintColor = [UIColor whiteColor]; 
    self.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor]; 
    self.navigationController.navigationBarHidden = NO; 
    self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 
    self.navigationController.navigationBar.translucent = NO; 
    self.title = @"Inbox"; 
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; 
+1

我已经回答了类似的问题: http://stackoverflow.com/questions/18929864 /如何-DO-I-变化的导航条,颜色在-IOS-18934411分之7#18934411 – RFG

回答

28

UINavigationItem不是一个视图,它没有颜色。

你,而不是想改变UIBarButtonItem色调的颜色。

使用UIAppearance代理,你可以做

[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]]; 

这将改变每个UIBarButtonItemtintColor在应用程序中。

您可以使用相同的策略来改变UINavigationBarbarTintColortitleTextAttributes

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // this will change the back button tint 
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]]; 
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; 

不幸的是there's no way of changing the translucent property using the proxy,所以你将不得不这样做的每个栏上。

+0

迷死人,这基本上是我在问,但这个完美的作品。谢谢! –

+0

欢迎您,并记住这只是iOS 7兼容。 –

+0

嗯......它改变了除

0

从iOS7开始,你可以为所有的导航项tintcolor只是为了保持一致的外观和感觉遍布应用:

if ([self.window respondsToSelector:@selector(setTintColor:)]) { 
     self.window.tintColor = [UIColor redColor]; 
} 

另外,也要看看我的答案这里推荐阅读和观看材料: StatusBar bug in iOS7?

+0

我认为用户询问'UINavigationBar'和'UIBarButtonItem',你的回答适用于超过他的要求。 – Roland

0

superViewDidLoad方法中。

self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 

它会改变导航项目颜色的颜色。 按钮也会发生同样的情况。

+0

这个问题是关于整个应用程序。 – DanSkeel

0

这适用于改变后退按钮颜色:

[[UINavigationBar appearance] setTintColor:[UIColor redColor]]; 

测试与iOS 9.3,iPhone和iPad。您的导航栏标题仍将使用默认颜色进行着色。这有点令人困惑。

1

斯威夫特答案

UINavigationBar.appearance().backgroundColor = UIColor.blackColor() 
UINavigationBar.appearance().barTintColor = UIColor.blackColor() 
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] 
UINavigationBar.appearance().tintColor = UIColor.blackColor() 
UIBarButtonItem.appearance().tintColor = UIColor.blackColor() 
UITabBar.appearance().backgroundColor = UIColor.blackColor() 
UITabBar.appearance().tintColor = UIColor.blackColor() 
UITabBar.appearance().unselectedItemTintColor = UIColor.darkGrayColor() 

把它放在你的AppDelegate的FUNC应用程序(应用程序:UIApplication的,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

相关问题