How to set the font size of navigation bar title
12,568
Solution 1
Add these lines to your viewDidLoad()
method:
self.navigationController?.navigationBar.topItem?.title = "Your title"
self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Your Font", size: 34)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
Solution 2
Update for swift 4
Presumably you want to set the tittle for UINavigationbar with system fontsize 30 and yellow color. The syntax would probably look like the followings:
navigationItem.title = "Your Title"
navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 30),NSAttributedStringKey.foregroundColor: UIColor.yellow]
Solution 3
try this...
let titleAttributes = [
NSFontAttributeName: UIFont(name: "your font name", size: 15)!
]
self.navigationController?.navigationBar.titleTextAttributes = titleAttributes
If you are using system font then
let titleAttributes = [
NSFontAttributeName: UIFont.systemFontOfSize(15)
]
self.navigationController?.navigationBar.titleTextAttributes = titleAttributes
Author by
mcfly soft
Updated on June 04, 2022Comments
-
mcfly soft about 2 years
I try to set the fontsize of my navigation title and other items. How can I do this ?
There are a lot of answers mentoining that we just can set this with the method uinavigationbar.setTitleTextAttributes, but this method doesn't exist (anymore)
Does someone know how to do ?
navigationBar = UINavigationBar(frame: CGRectMake(0, 0, fDialogWidth, navbarHeigth)) let navigationItem = UINavigationItem() navigationItem.title = sTitle; // Create left and right button for navigation item let leftButton = UIBarButtonItem(title: sBacklabel, style: UIBarButtonItemStyle.Plain, target: self, action: "backAction:") let rightButton = UIBarButtonItem(title: saddBookmark, style: UIBarButtonItemStyle.Plain, target: self, action: "addBookmarkAction:") // Create two buttons for the navigation item navigationItem.leftBarButtonItem = leftButton navigationItem.rightBarButtonItem = rightButton navigationBar.items = [navigationItem]; navigationBar.frame = CGRectMake(0, 0, screenwidth, navbarHeigth);