Change the navigation bar font

The question is simple and simple; unfortunately, the answer is no.

How can you change the font of the text in the UINavigationBar ?

+63
objective-c iphone uinavigationcontroller uinavigationbar
Apr 29 '11 at 12:30
source share
7 answers

From iOS 7 and later:

 NSShadow* shadow = [NSShadow new]; shadow.shadowOffset = CGSizeMake(0.0f, 1.0f); shadow.shadowColor = [UIColor redColor]; [[UINavigationBar appearance] setTitleTextAttributes: @{ NSForegroundColorAttributeName: [UIColor greenColor], NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20.0f], NSShadowAttributeName: shadow }]; 

From iOS 5 and later:

  [[UINavigationBar appearance] setTitleTextAttributes: @{ UITextAttributeTextColor: [UIColor greenColor], UITextAttributeTextShadowColor: [UIColor redColor], UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeFont: [UIFont fontWithName:@"Helvetica" size:20.0f] }]; 

Earlier than iOS 5:

 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)]; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:20.0]; label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; label.textAlignment = UITextAlignmentCenter; label.textColor =[UIColor whiteColor]; label.text=self.title; self.navigationItem.titleView = label; [label release]; 
+157
Apr 29 '11 at 12:32
source share

If you want to change the font in the interface itself (without any code), this is the way to do it in Xcode6:

1.) Locate the navigation bar view below the navigation controller scene enter image description here

2.) Change the font attributes of the header, color, and shadow in the Attributes Inspector. enter image description here

+15
Jan 30 '15 at 20:08
source share

The above answer works. I would add the following line to the last line. If I do not, it seems that the label is not centered correctly if there is a back button on the left side but no right button.

 ... [self.navigationItem.titleView sizeToFit]; [label release]; // not needed if you are using ARC 
+5
Apr 11 '12 at 8:50
source share

Updated for iOS 7:

 [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName, shadow, NSShadowAttributeName, [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]]; 

Courtesy of:

http://www.appcoda.com/customize-navigation-status-bar-ios-7/

+5
Oct 08 '13 at 1:44
source share

I don’t know why all the answers included a shadow. Adding lines that manipulate the shadow does nothing regarding changing the font of the text. These 2 lines of code will work for iOS 8.4 and Swift

 let attributesDictionary = [NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 14)!] navigationController!.navigationBar.titleTextAttributes = attributesDictionary 

The titleTextAttributes stores a dictionary that will determine the font, color, size, and other attributes of the title bar of the navigation bar.

+4
Aug 22 '15 at 2:38
source share

As in iOS 5, you can use the appearance proxy.

The answer is in a duplicate of this question: https://stackoverflow.com/a/464829/

+1
Dec 28 '12 at 5:24
source share
  NSShadow *shadow = [NSShadow new]; [shadow setShadowColor: [UIColor clearColor]]; [shadow setShadowOffset: CGSizeMake(0.0f, 1.0f)]; [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"TimeBurner" size:27.0f], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, shadow, NSShadowAttributeName,nil]]; 
+1
Mar 06
source share



All Articles