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.
how can i change comment font?
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.
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.
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.
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.
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,...
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)!]
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