UINavigationBar change title text color and font size

Sonu picture Sonu · May 15, 2014 · Viewed 9.2k times · Source

I want to change navigation title's font and color..so, for that i've done this below code..but its not working...

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) {


    NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                               [UIColor whiteColor],
                                               NSForegroundColorAttributeName,
                                               [UIFont fontWithName:@"MyFavoriteFont" size:20.0],
                                               NSFontAttributeName,
                                               nil];
    [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
    NSLog(@"setTitleTextAttributes");
}

why this code is not working?

Answer

ruyamonis346 picture ruyamonis346 · May 19, 2014

Apply Attributes to Navigationcontroller instance.

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) {
    NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                               [UIColor whiteColor],
                                               NSForegroundColorAttributeName,
                                               [UIFont fontWithName:@"MyFavoriteFont" size:20.0],
                                               NSFontAttributeName,
                                               nil];
    [self.transitionNavController.navigationBar setTitleTextAttributes:navbarTitleTextAttributes];
}

Hope this helps...