2

As you can see in the picture below, my UIViewController IS NOT a UINavigationController, it's a common UIViewController. What I did is I put a UINavigationBar using interface builder and above it I put a UIImage. The problem is that I want to change the font of this UINavigationBar. Anyone would have a clue on how to do it?

image with the problem

Usually, with a common UINavigationController I use the following code:

// this will appear as the title in the navigation bar
self.label = [[UILabel alloc] initWithFrame:CGRectZero];
self.label.backgroundColor = [UIColor clearColor];
self.label.font = [UIFont fontWithName:@"Copperplate" size:22];
self.label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
self.label.textAlignment = UITextAlignmentCenter;
self.label.textColor = [UIColor whiteColor]; // change this color
self.label.text = [self.navigationItem title];
self.navigationItem.titleView = label;
[label sizeToFit];
J. Steen
  • 15,470
  • 15
  • 56
  • 63
newton_guima
  • 1,569
  • 2
  • 18
  • 26

2 Answers2

1

Storyboard Solution

There's nothing wrong with the answer above but a really simple way to do this is to select the Navigation Bar in the storyboard. Then change the Title Font in the attributes inspector.

Title-Font

Nota Bene

This technique is also really useful when you want to change the font across an entire set of views whenever you are using a navigation controller. (Just change it in one place). Xcode 7.1.1 has a couple of bugs. One of those requires that you toggle the Bar Tint from the default to another color (you can always reset it to the default if needed) in order to see the font change.

Custom Fonts

The above is currently not working when selecting a custom font (as of Xcode 7.1.1). Please see the following SO Answer for a workaround if you need a custom font. (tldr; add an outlet to a button or label, change the custom font on that control, set that control as the UINavigationItem.titleView).

Community
  • 1
  • 1
Tommie C.
  • 12,895
  • 5
  • 82
  • 100
1

Well it should work the same way. I think you just need an IBOutlet for the UINavigationBar, or only for the UINavigationItem (the title for your UINavigationBar) and that's it.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • The way its described in the code doesnt work. I also tried to declare a property of a UINavigationBar and link it to the navigation bar in the IB but the Nav Bar doesnt have the same properties as a nav controller.. it didnt work at least.. i will try a IBOutlet to the navigation item only and then post it here.. But im still open to other ideas ;) – newton_guima Dec 06 '11 at 13:24
  • Having an IBOutlet to the navigationItem didnt worked? :S That's really strange. Yes please post it. – Rui Peres Dec 06 '11 at 13:54
  • Dude, it worked, i created a iboutlet of a UINavigationItem and linked it to the item Reference Outlet on IB.. it finally Worked.. Thanks!! – newton_guima Dec 07 '11 at 01:18