9

I am using navigation controller in my application and want to change title color of navigationBar.

I am doing so using below code

NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],UITextAttributeTextColor,nil];
    [self.navController.navigationBar setTitleTextAttributes:dic];

One more thing I am using ARC xcode 4.2 and this code is placed on appdelegate only

It is working fine in ios 4+ but not working on below versions.

Please help me how to do this from single code on appdelegate

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
Shivomkara Chaturvedi
  • 1,697
  • 7
  • 28
  • 42
  • The code you post is for iOS 5, if you want it to work on iSO 4 you won't be able to do it in a single line of code in the appdelegate. – rckoenes Jan 06 '12 at 09:59
  • 1
    this question is already answered in link http://stackoverflow.com/questions/599405/iphone-navigation-bar-title-text-color – Anil Kothari Jan 06 '12 at 10:10

5 Answers5

17

I was just looking for the same thing and found Alex R. R.'s easy solution using iOS 5:

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

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

Reference: iPhone Navigation Bar Title text color

Community
  • 1
  • 1
Max Strater
  • 540
  • 6
  • 17
9

You can recreate the titleView like that in your viewcontroller:

UILabel * titleView = [[UILabel alloc] initWithFrame:CGRectZero];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20.0];
titleView.shadowColor = [UIColor colorWithWhite:1.0 alpha:1.0];
titleView.shadowOffset = CGSizeMake(0.0f, 1.0f);
titleView.textColor = [UIColor redColor]; // Your color here
self.navigationItem.titleView = titleView;
[titleView sizeToFit];
[titleView release];

the other parameters are those wich are used in the native titleView.

**

Please look at Max Strater's answer below to have a more recent solution.

**

Zoleas
  • 4,869
  • 1
  • 21
  • 33
7

After iOS 5, just do this :

    nav1.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
Scott Solmer
  • 3,871
  • 6
  • 44
  • 72
Damien Romito
  • 9,801
  • 13
  • 66
  • 84
4

In iOS 7, just use:

self.navController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

Change [UIColor whiteColor] with whatever text color you want.

Enrique
  • 59
  • 3
2

in iOS 7 this is how you can change the color of Navbar title/text:

UIColor *red = [UIColor colorWithRed:254.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:1.0];

NSMutableDictionary *navBarTextAttributes = [NSMutableDictionary dictionaryWithCapacity:1];

[navBarTextAttributes setObject:red forKey:NSForegroundColorAttributeName ];

self.navigationController.navigationBar.titleTextAttributes = navBarTextAttributes;
grepit
  • 21,260
  • 6
  • 105
  • 81