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);
Change the Bar Style A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.
The title color of Navigation Bar can be changed in Storyboard. Go to Attributes inspector of Navigation Controller > Navigation Bar and set the desired color in Title Color menu. Save this answer.
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()]
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]
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With