In SwiftUI 5 UINavigationBar.appearance().titleTextAttributes doesn't work. You need to use one of the following to change the font in the title:
init () {
UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(name: "Georgia", size: 20)!]
// OR
UINavigationBar.appearance().largeTitleTextAttributes = [.font:UIFont.preferredFont(forTextStyle:.text-style)]
}
where .text-style could be found in UIFont.TextStyle documentation, e.g.
.caption
.body
.title1
.title2
.title3
etc
Update 1 (to answer a qs about exact code in comments)
struct ContentView: View {
init () {
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
UINavigationBar.appearance().largeTitleTextAttributes = [.font:UIFont.preferredFont(forTextStyle:.title2),
.foregroundColor:UIColor.systemBlue,
.paragraphStyle: paragraph
]
...
then in body I have this. You should probably pay attention to displayMode param
// Body is in the same ContentView struct. Settings from init will be used in navigationBarTitle
// listView() is just a custom function returning a SwiftUI's List()
var body: some View {
NavigationView {
listView()
.navigationBarTitle(
Text(self.accts.selCount <= 0 ? "Accounts" : "\(self.accts.selCount) selected")
,
displayMode:.large)