问题
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