Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the navigation bar's font

The question is plain easy and simple, the answer unfortunately not.

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

like image 447
Joetjah Avatar asked Apr 29 '11 12:04

Joetjah


People also ask

How do I change the navigation bar on my Iphone?

In the Safari app , you can choose the layout that works best for you. Depending on the layout, the search field appears at the top (Single Tab layout) or bottom (Tab Bar layout) of the screen. Go to Settings > Safari, then scroll down to Tabs. Select either Tab Bar or Single Tab.


2 Answers

If you wanted to change the font in the Interface Builder itself (without any code) here is the way to do it in Xcode6:

1.) Find the Navigation Bar view under the Navigation Controller Scene enter image description here

2.) Change the Title Font, Color and Shadow attributes in the Attributes Inspector. enter image description here

like image 39
inder Avatar answered Oct 08 '22 12:10

inder


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]; 
like image 96
Aravindhan Avatar answered Oct 08 '22 12:10

Aravindhan