I have over 20 UINavigationBars
need to change the font of their titles, and based on all the tutorials I saw, there is one way to do this which is change the bar UILabel
, so I used below code:
+ (void) applyFontForUINavigationItem:(UINavigationItem *)navItem withTitle:(NSString *) title{
UILabel *navLabel = [Util generateNabBarLabel withText:title];
[navLabel setFontName:FONT_NAME_BOLD];
navItem.titleView = navLabel;
}
It works fine, but I don't want to add this odd line in all my ViewControllerss
' viewDidLoad
, is there a legal way to do this even with subclassing ?
EDIT: I am using custom font from a ttf file same as here.
and after applying apperance I got this:
Note that setFont
doesn't work for Arabic Custome font according to this so am using below for UILabels:
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:myLabel.text attributes:@{ NSFontAttributeName : myLabel.font, NSLigatureAttributeName: @1}];
myLabel.attributedText = attributedString;
And it works fine (for UILabel).