2016-09-26 40 views
2

在我的视图控制器来设置我的栏按钮项类似这样的设置栏按钮项目颜色在应用程序委托

[self.navigationItem.backBarButtonItem setTintColor:[UIColor whiteColor]]; 

但我想达到的目标是将其设置在我的应用程序委托,这样我所有的酒吧在所有视图控制器按钮项目是白色的类似于这样

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

我可以得到它的工作文字的东西,但我想改变它的图像

样本图片,

Sample Image

编辑: 我怎么设置我的图像

Image

+1

试试这个 '[外观的UIBarButtonItem] setTitleTextAttributes:[NSForegroundColorAttributeName:[的UIColor whiteColor] forState:UIControlStateNormal' –

+0

@ New16它适用于文本,但不工作在图像上。你有解决方案来设置图像上的色调颜色? –

+0

请参阅此文章https://www.appcoda.com/customize-navigation-bar-back-butto/。在这篇文章中,他们提到如何改变色调并在应用程序委托中自定义导航栏。 @Lian van der Vyver – KAR

回答

0

//使在Appdelegate.h

@property(nonatomic)UIColor* appDelColor; 

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

//设置的AppDelegate颜色

appDelegate.appDelColor= [UIColor redColor]; 

//得到的AppDelegate颜色

UIColor *appDELColor=appDelegate.appDelColor; 
+0

谢谢,但这不是我要找的。我试图在应用程序委托中设置我的酒吧按钮项目颜色,而不是应用程序委托中的颜色。 –

+0

ok然后你可以在appdelegate.h中创建@propery并将它分配到appdelegate.m,然后你可以在你想要的地方使用它 –

1

您可以使用相同的策略来改变UINavigationBar的barTintColor和titleTextAttributes:

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

编辑:

UIImage *selectedImage = [[UIImage imageNamed:@"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
+0

如果你认为它的工作,请接受答案。 –

+0

它适用于文本,但不适用于图像。你有解决方案来设置图像上的色调颜色? –

+0

你想更改UINavigationBar图像的颜色? –

0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [UINavigationBar appearance].tintColor = [UIColor whiteColor]; 

    return YES; 
} 

愿这将帮助你.. :)