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

1

6

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!

Gadmann answered 11/10, 2020 at 12:40 Comment(0)
P
9

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")
    }
Parquetry answered 11/10, 2020 at 13:2 Comment(1)
Isn't UINavigationBar a UIKit thing? What is the equivalent approach in SwiftUI?Cacomistle

© 2022 - 2024 — McMap. All rights reserved.