iOS 7导航栏文本和箭头颜色

我想将导航栏的背景设置为黑色,并将其中的所有颜色设置为白色。


因此,我使用了以下代码:


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

但是后退按钮的文字颜色,箭头和方向键仍为默认蓝色。

如何更改下图所示的颜色?


繁星淼淼
浏览 968回答 3
3回答

一只名叫tom的猫

UINavigationBar从iOS 7开始,某些属性的行为已更改。您可以在下面显示的图像中看到:我想与您分享两个美丽的链接。有关更多详细信息,您可以通过以下链接:iOS 7 UI过渡指南。如何为iOS更新您的应用程序7。苹果文档的barTintColor说:除非您将半透明属性设置为NO,否则默认情况下此颜色为半透明。样例代码:self.navigationController.navigationBar.barTintColor = [UIColor blackColor];self.navigationController.navigationBar.tintColor = [UIColor whiteColor];[self.navigationController.navigationBar  setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];self.navigationController.navigationBar.translucent = NO;

慕勒3428872

这花了我大约半天时间才弄清楚,但这对我有用。在用于初始化navigationController的rootViewController中,将以下代码放入viewDidAppear方法中://set bar color[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]];//optional, i don't want my bar to be translucent[self.navigationController.navigationBar setTranslucent:NO];//set title and title color[self.navigationItem setTitle:@"Title"];[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];//set back button color[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];//set back button arrow color[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

MMMHUHU

Swift3,iOS 10要全局分配颜色,请在AppDelegate中didFinishLaunchingWithOptions:let textAttributes = [NSForegroundColorAttributeName:UIColor.white]UINavigationBar.appearance().titleTextAttributes = textAttributesSwift 4,iOS 11let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]UINavigationBar.appearance().titleTextAttributes = textAttributes
打开App,查看更多内容
随时随地看视频慕课网APP