Reputation:
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).
Upvotes: 0
Views: 297
Reputation: 79
1.If edit your project in code I have a idea by inheriting a super navigation controller which has changed the navigation bar
tile font size
.
2.If you edit your project in storyboard
, you can search .storyboard
in your project, in storyboard
you can easy edit the navigationbar
to change the font
.
I takon a photo for you below:
Upvotes: 0
Reputation: 31
try to use with UIAppearance feature to set the navigation bar tile font size.
Upvotes: 1
Reputation: 119041
You can use the appearance delegate to change the font via the title text attributes:
[[UINavigationBar appearance] setTitleTextAttributes:@{ UITextAttributeFont : [UIFont fontWithName:FONT_NAME_BOLD size:17] }];
Upvotes: 0