SwiftUI:如何在 NavBarTitle 中获取 .serif(纽约)字体 [英] SwiftUI: How to get .serif (New York) font in NavBarTitle

查看:93
本文介绍了SwiftUI:如何在 NavBarTitle 中获取 .serif(纽约)字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有关于如何在导航栏标题中使用 Apples New York 字体的简单解决方案?我尝试了以下方法,但没有成功:

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)))

它只是默认回默认的 SF 字体.

It just defaults back to the default SF font.

非常感谢任何帮助!谢谢!

Any help is greatly appeciated! Thanks!

推荐答案

这里是可能的解决方案的演示.使用 Xcode 12/iOS 14 测试

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")
    }

这篇关于SwiftUI:如何在 NavBarTitle 中获取 .serif(纽约)字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆