Ask Your Question

How can I modify the font size of the NavigationTitle in SwiftUI?

asked 2022-11-20 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-12 18:00:00 +0000

scrum gravatar image

You can modify the font size of the NavigationTitle in SwiftUI by setting the titleTextAttributes modifier on the navigation bar. Here's an example:

NavigationView {
    Text("Hello World!")
        .navigationTitle("My Title")
        .navigationBarTitle("My Title")
.onAppear {
    let appearance = UINavigationBarAppearance()
    appearance.largeTitleTextAttributes = [
        NSAttributedString.Key.font: UIFont.systemFont(ofSize: 36)
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().compactAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance

In this example, we set the font of the title to be a system font with a size of 36. You can adjust the size to fit your needs. The appearance object is used to set the font for all the different states of the navigation bar (standard, compact, and scroll edge). Finally, we apply the appearance to the navigation bar using the UINavigationBar.appearance() method.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2022-11-20 11:00:00 +0000

Seen: 10 times

Last updated: Nov 12 '21