我该如何将状态栏的背景颜色更改为不同的颜色?我正在使用NavigationView和ZStack。
我希望将绿色导航栏上方的白色区域变为绿色。请问如何更改?
我的尝试
这是我的导航栏代码:
这是我为应用程序背景颜色编写的代码:
init() {
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor : UIColor(#colorLiteral(red: 0.8745098039, green: 0.3411764706, blue: 0, alpha: 1))]
UINavigationBar.appearance().backgroundColor = UIColor(named: "backgroundColor")
}
这是我为应用程序背景颜色编写的代码:
var body: some View {
NavigationView {
ZStack {
Color("backgroundColor")
.edgesIgnoringSafeArea(.all)
}
.navigationBarTitle(Text("Agenda"))
}
}
}
最后但同样重要的是我的场景代理代码:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let newAppearance = UINavigationBarAppearance()
newAppearance.configureWithOpaqueBackground()
newAppearance.backgroundColor = .black
newAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = newAppearance
//Other code for displaying the first screen
}