Alex Rivera | Logout

Changing NavigationItem’s font

Asked 2010-05-05T08:19:53.893
19

I have used this code to change a NavigationItem’s title:

self.navigationItem.title = @"My Name is ABC";

How can I change the font size and font as well?

Edit
Report

2 Answers

32

Sample Code :

CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:8.0];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = @"Sample custom Title With small Fonts ";
self.navigationItem.titleView = label;
answered 2010-05-05T08:51:02.840
0

I have found some good answer for this .I think it's similar to the accepted answer however please find it in some more detail.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  

   self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    

   if (self){
     // this will appear as the title in the navigation bar    
     UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];      
    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 yellowColor]; // change this color      
    self.navigationItem.titleView = label;          
    label.text = NSLocalizedString(@"PageThreeTitle", @"");       
    [label sizeToFit];    
 }    
 return self;

} 

For more details, Please refer this Link

answered 2012-02-24T05:20:49.743

Your Answer