1

From a UITableView I am pushing another view controller with another UITableView onto the stack using this code:

// allocate and create instance of categories view controller
TJKCategoriesViewController *categoriesViewController = [[TJKCategoriesViewController alloc] init];

// push it onto the top of the navigation controller's stack
[self.navigationController pushViewController:categoriesViewController animated:YES];

When I am in the viewDidLoad method for the TJKCategoriesViewContoller I am changing the title using this code:

self.title = @"Categories";

This works just fine. However the "Categories" title is coming out the color of black and I would like it to be a different color. I've tried things like tintColor, but self.title doesn't have this property.

Does anyone have any suggestions?

Thanks, Glenn

glennsep
  • 164
  • 3
  • 10
  • Possible duplicate of [How to change Navigation Bar color in iOS 7?](http://stackoverflow.com/questions/18929864/how-to-change-navigation-bar-color-in-ios-7) – R P Feb 16 '16 at 01:04

3 Answers3

2

You can create a UILabel and set it to UINavigationItem's titleView. See Apple doc: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationItem_Class/#//apple_ref/occ/instp/UINavigationItem/titleView

Some codes:

- (void)setMyTitle:(NSString *)title
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.navigationController.view.bounds.size.width - 100, 44)];
    titleLabel.text = title;
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textColor = ...
    ...
    self.navigationItem.titleView = titleLabel;
}
Harrison Xi
  • 766
  • 1
  • 5
  • 23
  • Thanks, this worked too. I don't have enough reputation points to increment the useful counter yet. – glennsep Feb 17 '16 at 12:00
0

You can use the tintColor property of the NavigationBar:

self.navigationController.navigationBar.tintColor = [UIColor blueColor];

If you want to make tintColor changes to be global, you can use the NavigationBar appearance proxy.

[[UINavigationBar appearance] setTintColor: [UIColor blueColor]];

R P
  • 1,173
  • 2
  • 11
  • 20
0

Add this to your viewDidLoad method:

NSArray *keys = [NSArray arrayWithObjects: NSForegroundColorAttributeName, NSFontAttributeName, nil];
NSArray *objs = [NSArray arrayWithObjects: [UIColor redColor], [UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0f], nil];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjects:objs forKeys:keys];

You can customize the font and the color

metronic
  • 455
  • 5
  • 15