SwiftUI: Status Bar Text Color

To change the status bar text color, you need to edit the UIHostingController call in the SceneDelegate. You can do this by creating your own file, named: HostingController, and having that file contain the following code:

import SwiftUI

final class HostingController<T: View>: UIHostingController<T> {
    override var preferredStatusBarStyle: UIStatusBarStyle {

and then in the scene delegate changing the line:

window.rootViewController = UIHostingController(rootView: contentView)


window.rootViewController = HostingController(rootView: contentView)

And voila, you have changed the status bar style.

iPhone - Before
iPhone - After

2 thoughts on “SwiftUI: Status Bar Text Color

  1. Isn’t it forcing to show light content, How does it work for dark mode. Is Der any solution which works automatically for both modes.

    1. Sorry this is very late, but the best way I have found to differentiate for dark mode is to get the colorscheme by putting this at the top of your struct with: @Environment(\.colorScheme) var colorScheme

      Then to get the current colorscheme you can do: ‘colorScheme == .light ? Color.lightColor : Color.darkColor’

Leave a Reply

Your email address will not be published. Required fields are marked *