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

不想你离开。 提交于 2021-01-28 07:50:47

问题


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:


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

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

var body: some View {
    NavigationView {
        VStack {

             // ...

        }.navigationTitle("New York")
    }


来源:https://stackoverflow.com/questions/64304116/swiftui-how-to-get-serif-new-york-font-in-navbartitle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!