如何在SwiftUI中更改.navigationBarTitle字体? [英] How change .navigationBarTitle font in SwiftUI?
本文介绍了如何在SwiftUI中更改.navigationBarTitle字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将SwiftUI与Xcode 11结合使用,我想用以下几行代码来更改 NavigationBarTitle
字体:
I'm using SwiftUI with Xcode 11 and I want to change NavigationBarTitle
font with these lines of codes:
.navigationBarTitle (Text("Navigation Bar Title"), displayMode: .inline)
.font(.subheadline)
但是什么也没发生.有任何建议或评论吗?
but nothing happened. any suggestion or comment?
推荐答案
在SwiftUI中,目前我们无法直接更改 navigationBarTitle
字体,但是您可以像这样更改NavigationBar的外观,>
In SwiftUI, at this point we can not change the navigationBarTitle
font directly, but you can change navigationBar appearance like this,
struct YourView: View {
init() {
//Use this if NavigationBarTitle is with Large Font
//UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(name: "Georgia-Bold", size: 20)!]
//Use this if NavigationBarTitle is with displayMode = .inline
UINavigationBar.appearance().titleTextAttributes = [.font : UIFont(name: "Georgia-Bold", size: 20)!]
}
var body: some View {
NavigationView {
Text("Hello World!")
//.navigationBarTitle("TEST")
.navigationBarTitle (Text("TEST"), displayMode: .inline)
}
}
}
我希望它能对您有所帮助.谢谢!
I hope it will help you. Thanks!!
这篇关于如何在SwiftUI中更改.navigationBarTitle字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文