天天看點

如何修改IOS7 Navigation Bar上的傳回按鈕文本顔色

我想設定Navigation Bar的背景顔色為黑色,然後所有内部顔色為白色.

是以,我用了這段代碼:

[[UINavigationBar appearance] setTitleTextAttributes:
      [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor whiteColor],
      NSForegroundColorAttributeName,
      [UIColor whiteColor],
      NSForegroundColorAttributeName,
      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
      NSForegroundColorAttributeName,
      [UIFont fontWithName:@"Arial-Bold" size:0.0],
      NSFontAttributeName,
      nil]];
           

但是,傳回按鈕文本顔色,箭頭顔色以及導航欄按鈕的顔色仍然為預設顔色,怎麼修改它們?

解決方法 1:

自從IOS7後UINavigationBar的一些屬性的行為發生了變化.你可以在下圖看到:

如何修改IOS7 Navigation Bar上的傳回按鈕文本顔色

現在,如果你要修改它們的顔色,用下面的代碼:

self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;