Home > OS >  Status bar color in iOS 16
Status bar color in iOS 16

Time:01-20

Thanks for taking your time to help others.

enter image description here

Changing

  • Status bar style: Light Content

gives:

enter image description here

You can also change the status bar text colour on a per view basis, making sure you set

  • View controller-based status bar appearance: YES

then wrapping your view in a NavigationStack, and adding the following toolbar modifiers:


.toolbarBackground(.mint, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarColorScheme(<colorScheme>, for: .navigationBar)

for example:

struct ContentView: View {
    
    var body: some View {
        NavigationStack {
            TestView(colorScheme: .dark)
        }
    }
}

struct TestView: View {
    
    let colorScheme: ColorScheme
    
    var body: some View {
        ZStack {
            Color.mint
                .ignoresSafeArea()
            VStack {
                Text("Hello")
                NavigationLink("Push") {
                    TestView(colorScheme: .dark)
                }
            }
        }
        .toolbarBackground(.mint, for: .navigationBar)
        .toolbarBackground(.visible, for: .navigationBar)
        .toolbarColorScheme(colorScheme, for: .navigationBar)
    }
}

gives:

enter image description here

  • Related