2017-03-16 150 views
0

navigationBar是黑色的:黑色導航欄標題顏色可以更改嗎?

self.navigationController.navigationBar.barStyle = UIBarStyleBlack; 

但標題不能改變文字顏色,它有沒有效果,爲什麼呢?

NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]; 
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes]; 
+0

你們是不是要設置從你的'UIViewController'故事板標題?如果是,那麼你應該在故事板中選擇* navigation item *並設置其標題。它應該會自動變成白色。 – Rikh

+0

來自代碼,不存在 –

+0

默認情況下它不是白色的?它可能是文本沒有設置? – Rikh

回答

0

嘗試使用此代碼:

NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
              [UIColor whiteColor],UITextAttributeTextColor, 
              [UIColor blackColor], UITextAttributeTextShadowColor, 
              [NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil]; 

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes]; 
0

試一下這個code.You可以很容易地改變你的標題顏色:)

self.navigationController.navigationBar.tintColor = White; 
self.navigationController.navigationBarHidden=NO; 
self.navigationItem.title = @"yourTitle"; 
[self.navigationController.navigationBar setTitleTextAttributes: 
@{NSForegroundColorAttributeName:White}]; 
self.navigationController.navigationBar.barTintColor = [UIColor blackColor]; 
0
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:kBoldFontName size:16],NSForegroundColorAttributeName:[UIColor blueColor]}]; 

這是爲我工作的罰款請嘗試一次。

0

我嘗試下面的代碼,它正在fine.I我使用Xcode中8和iOS 10.2

self.navigationController.navigationBar.barStyle = UIBarStyleBlack; 

self.navigationItem.title = @"your Title here"; 

[self.navigationController.navigationBar setTitleTextAttributes: 
    @{NSForegroundColorAttributeName:[UIColor greenColor]}]; 

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

enter image description here