This is a SwiftUI question, not a UIKit one. :)
I'm trying to set a different font for the navigation bar title using SwiftUI. My suspicion is that this isn't supported yet. Here's what I've tried:
var body: some View { NavigationView { .navigationBarTitle(Text("Dashboard").font(.subheadline), displayMode: .large) } }
No matter what I do with the .font
settings, it doesn't change the text. I've also tried setting a custom font and removing the displayMode
property.
Has anyone been able to get this to work?
To customize a navigation bar title view in SwiftUI, we simply set ToolbarItem of placement type . principal to a new . toolbar modifier.
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.
Show activity on this post. let navigation = UINavigationBar. appearance() let navigationFont = UIFont(name: "Custom_Font_Name", size: 20) let navigationLargeFont = UIFont(name: "Custom_Font_Name", size: 34) //34 is Large Title size by default navigation.
In SwiftUI, at this point we can not change the navigationBarTitle
font directly, but you can change navigationBar appearance like this,
struct YourView: View { init() { //Use this if NavigationBarTitle is with Large Font UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(name: "Georgia-Bold", size: 20)!] //Use this if NavigationBarTitle is with displayMode = .inline //UINavigationBar.appearance().titleTextAttributes = [.font : UIFont(name: "Georgia-Bold", size: 20)!] } var body: some View { NavigationView { Text("Hello World!") .navigationBarTitle(Text("Dashboard").font(.subheadline), displayMode: .large) //.navigationBarTitle (Text("Dashboard"), displayMode: .inline) } } }
I hope this will help you. Thanks!!
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