2016-09-26 64 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; 
} 

願這將幫助你.. :)