1

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
    }
}
HangarRash
  • 7,314
  • 5
  • 5
  • 32

1 Answers1

0

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.

jp21
  • 296
  • 2
  • 8
  • Yes this works temporarily but there are couple of concerns: 1. It seems like `UINavigationBar` belongs to UIKit and not swiftUI (Clarify me if I am wrong because I am new to this) 2. What if i want to change other properties (If you can attach some reference link where I can get more help) Thnx – Gaurang Patel Apr 01 '23 at 08:46
  • 1. You don't need to import UIKit for UINavigationBar (and UIFont) - it works just with SwiftUI.  2. You can change all other properties associated with UINavigationBar.appearance() in the same manner. You can of course set your own custom fonts (e.g. `[.font : UIFont(name: "Georgia-Bold", size: 10)!]`. Here’s [some](https://youtu.be/mn5LlrF7Ih8?t=389) [examples](https://pacugindre.medium.com/customizing-swiftui-navigation-bar-8369d42b8805) I found. – jp21 Apr 01 '23 at 17:18