Saj*_*jad 4 ios swift swiftui xcode11
我正在将SwiftUI与Xcode 11结合使用,我想NavigationBarTitle用以下代码行更改字体:
.navigationBarTitle (Text("Navigation Bar Title"), displayMode: .inline)
.font(.subheadline)
Run Code Online (Sandbox Code Playgroud)
但是什么也没发生。有什么建议或意见吗?
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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
I hope it will help you. Thanks!!
| 归档时间: |
|
| 查看次数: |
1231 次 |
| 最近记录: |