Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change navigation bar title font - swift

I have a title in my navigation bar and a i want to change it to custom font. I've found this line of code, but it's for when you have a navigation controller.

self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "LeagueGothic-Regular", size: 16.0)!,                                                               NSForegroundColorAttributeName: UIColor.whiteColor()] 

But i don't have any navigation controller. I added navigation bar manually to my view.

enter image description here

enter image description here

how can i change comment font?

like image 283
Hos Ap Avatar asked Sep 11 '16 17:09

Hos Ap


People also ask

How do I change the font in SwiftUI?

Hold the command key and click the text to bring up a pop-over menu. Choose Show SwiftUI Inspector and then you can edit the text/font properties.

How to customize a navigation bar title view in SwiftUI?

To customize a navigation bar title view in SwiftUI, we simply set ToolbarItem of placement type .principal to a new toolbar modifier. Text("Hello, SwiftUI!") <1> Because this is a customize of navigation bar title, a view needs to be embedded inside a NavigationView. <2> Set .toolbar modifier to a root view of NavigationView.

How to change the color of navigation bar and title text?

To change the color of the navigation bar and the title text, we can use UINavigationBarAppearance, which is available since iOS 13. We hereby make a class Theme with a static method as follows, which will come in handy when we need it for some setup in our View or elsewhere.

How do I set the navigation item title on the toolbar?

The navigationItem property is an instance of UINavigationItem, which has four major properties: a title, a left bar button, a right bar button and a prompt. To set the title on the toolbar , you set the string for the title property. For example add this to the ViewController class Build and run. The root view now has One as a title.

How do I change the font size and color of titles?

Swift version: 5.1 If you're setting title's in a navigation bar, you can customize the font, size and color of those titles by adjusting the titleTextAttributes attribute for your navigation bar. To do this on a single bar just set it directly whenever you want to; to change all bars,...


1 Answers

Try this:

Objective-C

[[UINavigationBar appearance] setTitleTextAttributes:attrsDictionary]; 

Swift 3

self.navigationController.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "CaviarDreams", size: 20)!] 

Swift 4

self.navigationController.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont(name: "CaviarDreams", size: 20)!] 
like image 53
KAR Avatar answered Oct 11 '22 17:10

KAR