黑色导航栏标题颜色可以改变吗?

时间:2017-03-16 10:07:26

标签: ios objective-c uinavigationcontroller uinavigationbar

我的navigationBar是黑色的:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

但是不能改变标题中的textcolor,它没有效果,为什么?

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

4 个答案:

答案 0 :(得分:0)

尝试使用此代码:

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

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

答案 1 :(得分:0)

试试此代码。您可以轻松更改标题颜色:)

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];

答案 2 :(得分:0)

awk 'NR==FNR{a[$2]=$1;next}($1 in a){print a[$2] " " $2}' file1 file2 

对我来说工作正常,请尝试一次。

答案 3 :(得分:0)

我尝试下面的代码它工作正常。我正在使用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