SwiftUI: How to get .serif (New York) font in NavBarTitle

Viewed 1097

is there any simple solution on how to use Apples New York font within the navigationBarTitle? I tried the following, but without success:

.navigationBarTitle(Text("TestTitle").font(.system(.largeTitle, design: .serif)))

It just defaults back to the default SF font.

Any help is greatly appeciated! Thanks!

1 Answers

Here is a demo of possible solution. Tested with Xcode 12 / iOS 14

demo

init() {
    UINavigationBar.appearance().largeTitleTextAttributes = 
       [.font: UIFont(descriptor: 
               UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle)
               .withDesign(.serif)!, size: 48)]
}

var body: some View {
    NavigationView {
        VStack {

             // ...

        }.navigationTitle("New York")
    }
Related