I want the color above the titlebar of NavigationView to remain the same, even when I scroll the list. I've tried using UINavigationBar
to set it, but it doesn't work in unsafe area, and tt still turns gray when sliding down.
import SwiftUI
struct ContentView: View {
init(){
UINavigationBar.appearance().backgroundColor = UIColor.blue // it doesn't works in unsafe area
}
var body: some View {
TabView {
NavigationView{
List{
ForEach((1...10).reversed(), id: \.self) {
Text("list \($0)")
}
}.toolbar(content: {
ToolbarItem(placement: .principal, content: {
Text("Title Bar")
.bold()
.frame(maxWidth: .infinity,maxHeight: .infinity, alignment: .center)
.background(Color.red) // it doesn't works
})})
.navigationBarTitleDisplayMode(.inline)
}.tabItem {
Image(systemName: "person")
Text("tag1")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
the preview