繁体   English   中英

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

[英]Can black navigationbar title color change?

我的navigationBar是黑色的:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

但是不能更改标题中的textcolor,它没有任何作用,为什么?

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

尝试使用以下代码:

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

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

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

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];
   [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:kBoldFontName size:16],NSForegroundColorAttributeName:[UIColor blueColor]}];

对我来说很好,请再试一次。

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

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM