Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar change title text color and font size

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?

like image 579
Sonu Avatar asked May 15 '14 06:05

Sonu


People also ask

How do I change the font style of the navigation bar title in Swift?

let navigation = UINavigationBar. appearance() let navigationFont = UIFont(name: "Custom_Font_Name", size: 20) let navigationLargeFont = UIFont(name: "Custom_Font_Name", size: 34) //34 is Large Title size by default navigation. titleTextAttributes = [NSAttributedStringKey. foregroundColor: UIColor.


1 Answers

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...

like image 80
ruyamonis346 Avatar answered Oct 08 '22 01:10

ruyamonis346