I want to be able to set the font of my apps navigation bar back button without doing anything too crazy and without losing any other design characteristics of the button (i.e. I want to keep the arrow).
Right now I use this in viewDidAppear:
to set the font of the normal bar button items.
for (NSObject *view in self.navigationController.navigationBar.subviews) {
if ([view isKindOfClass:[UIButton class]]) {
[((UIButton*)view).titleLabel setFont:[UIFont
fontWithName:@"Gill Sans"
size:14.0]];
}
}
However this makes no change on the back button, regardless of which UIViewController
this code is applied to (root, current, etc.).
Swift version of the all mentioned above (excerpt from the original answer) :
More goodies:
https://stackoverflow.com/a/28347428/469614
To change the appearance of the text in all
UIBarButtonItems
appearing in allUINavigationBars
, do the following inapplication:didFinishLaunchingWithOptions:
UPDATE: iOS7 friendly version
Swift:
NOTE: this changes ALL instances of
UIBarButtonItem
, not just those contained within aUINavigationBar
Swift3:
In Swift3:
Note: you only have to do this once for the Navigation controller.
Use this instead in your AppDelegate or where the NavigationController is initialized, method available in iOS 5 and above
For anyone that did not fully got this to work, here is how i did it, including popped back to the Root ViewController in IOS7:
popToRoot ViewController:
Maybe someone may have use of this.
Swift 3.0+
AppDelegate.swift