Search code examples
swiftuinavigation

Change font size of NavigationTitle in SwiftUI


I wanted to change the font size of the navigationTitle to .footnote I tried to search but all the solutions i came up on internet were related to navigationBarTitle

Here is my Code:

var body: some View {
    NavigationView {
        List {
            CoverImageView()
                .frame(height: 300)
                .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
        }
        .listStyle(PlainListStyle())
        .navigationTitle("Title")
//wanted to make "Title" appear as .footnote fontsize
    }
}

Solution

  • Changing the appearance of the UINavigationBar also seems to affect the navigationTitle:

    struct ContentView: View {
        init() {
            UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont.preferredFont(forTextStyle: .footnote)]
            UINavigationBar.appearance().titleTextAttributes = [.font : UIFont.preferredFont(forTextStyle: .footnote)]
        }
    
        var body: some View {
            NavigationView {
                List {
                    CoverImageView()
                        .frame(height: 300)
                        .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
                }
                .listStyle(PlainListStyle())
                .navigationTitle("Title")
            }
        }
    }
    

    (Code based on link)

    I hope this helps.