Status Bar Color Not being modified SwiftUI

247 Views Asked by At

Thanks for taking your time to help others :)

Problem description:

I'm starting a new iOS 14-16 app with SwiftUI. In this new app, we removed AppDelegate and SceneDelegate logic, just trying to simplify, using just the WindowGroup.

The thing is, all the views in the App has to present a white status bar (for dark content) and, in that way, I tried to configure the status bar a single time, at Info.plist... But nothing worked, every page on the internet asks me to do the same...

And, has to be shown alongside the launch screen, cause is also dark content-like.

What I'm doing:

On Info.plist, I apply the following values:

  • View controller-based status bar appearance with value NO
  • Status bar style with value Dark Content

And maybe a little redundant but on Project > General > Deployment Info > Status Bar Style: Dark Content

Simple code of the actual View:

import SwiftUI

@main
struct ExampleApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                VStack {
                    Text("This is a simple view. Status bar has to be white.")
                }
            }
            .navigationViewStyle(StackNavigationViewStyle())
        }
    }
}

Questions

  1. Why is not applying the color ?
  2. Is there any way to modify it, that's not deprecated and compatible with no Scene/AppDelegate + WindowGroup ?
  3. Does .preferredColorScheme(.dark) affects in any way to native elements such as .contextMenu() ? Or just to the tint of the status bar?
1

There are 1 best solutions below

0
On

Try to add this initializer to the main struct:

init() {
    // Navigation Bar Title font and background colour.
    let navBarAppearance = UINavigationBar.appearance()
    // Background
    navBarAppearance.backgroundColor = UIColor.blue
    // Font colour
    navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.orange]
    navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.orange]    
}

That should help if I understood your issue correctly.