Search code examples
objective-ccocoa-touchfontsuinavigationbartitle

Change UINavigationBar font properties?


I have an UINavigationBar added to my UIViewController view. I want to change the fonts properties. Note that I want to change a UINavigationBar not controller. In my app where I use UINavigationController I use self.navigationItem.titleView = label; to display the custom label.

How can I accomplish to have a custom title in my UINavigationBar?

P.S I use this to set the title text self.navBar.topItem.title = @"Information"; of my UINavigationBar.


Solution

  • From iOS 5 onwards we have to set title text color and font of navigation bar using titleTextAttribute Dictionary(predefined dictionary in UInavigation controller class reference).

    [[UINavigationBar appearance] setTitleTextAttributes: 
        [NSDictionary dictionaryWithObjectsAndKeys: 
            [UIColor blackColor], NSForegroundColorAttributeName, 
               [UIFont fontWithName:@"ArialMT" size:16.0], NSFontAttributeName,nil]];
    

    The below tutorial is the best tutorial for customization of UIElements like UInavigation bar, UIsegmented control, UITabBar. This may be helpful to you

    http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5