2

I want to change the UINavigationBar titleColor.

I also want to change the textColor of the UINavigationBar backButton.

I am using iPhone Os sdk 3.1.2

Roland Keesom
  • 8,180
  • 5
  • 45
  • 52
Rupesh
  • 7,866
  • 11
  • 41
  • 58

5 Answers5

2

This worked for me.

Using this you can change the color of all of the navigation buttons:

 [[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

Replace redColor with the following to adjust the color of the buttons:

colorWithRed:0/255.0 green:144/255.0 blue:200/255.0 alpha:1.0// pick your color using this

Be sure to put this in the view controller that pushes. Not the view controller where you want to see this back button color.

SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
1

One part of this question has already been answered.

Then, to change the back button title color, I would suggest creating a custom button with a label:

UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:yourViewWithColoredText];
navigationItem.leftBarButtonItem = buttonItem; // assign it as the left button

yourViewWithColoredText should be a custom view containing your colored text. Then depending on what you want, you could make it look like a standard back button.

Community
  • 1
  • 1
Jean Regisser
  • 6,636
  • 4
  • 32
  • 32
0

You can set the titleView, defined in UINavigationBar.h as:

 @property(nonatomic,retain) UIView *titleView;
// Custom view to use in lieu of a title. May be sized horizontally. Only used when item is topmost on the stack.

Pop your own UILabel in there with whatever color you want.

Anthony Pegram
  • 123,721
  • 27
  • 225
  • 246
Kenny Winker
  • 11,919
  • 7
  • 56
  • 78
0
UIBarButtonItem *button = [[UIBarButtonItem alloc] init];
[button setTintColor:[UIColor redColor]];
Bhoopi
  • 6,523
  • 3
  • 22
  • 16
0

Set the title on UINavigationBar on iOS 5 & 6

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:UITextAttributeTextColor]];

On iOS 7

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor blackColor]};


Set the textColor on all UIBarButtonItem

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [UIColor blackColor], UITextAttributeTextColor,
                                    [UIColor clearColor], UITextAttributeTextShadowColor, nil];

[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];
Roland Keesom
  • 8,180
  • 5
  • 45
  • 52