如何更改导航栏中的背景或颜色? [英] How can the background or the color in the navigation bar be changed?
本文介绍了如何更改导航栏中的背景或颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我找不到任何方法来更改SwiftUI中导航栏的颜色/背景.有提示吗?
Currently I couldn't find any method to change the color/background of the navigation bar in SwiftUI. Any tips?
推荐答案
在SwiftUI中,目前我们不能直接对其进行更改,但是您可以像这样更改NavigationBar的外观,
In SwiftUI, at this point we can not change it directly, but you can change navigationBar appearance like this,
struct YourView: View {
init() {
UINavigationBar.appearance().backgroundColor = .orange
//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(Text("Dashboard").font(.subheadline), displayMode: .large)
//.navigationBarTitle (Text("Dashboard"), displayMode: .inline)
}
}
}
我希望这会对您有所帮助.谢谢!
I hope this will help you. Thanks!!
这篇关于如何更改导航栏中的背景或颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文