-3

My statusBar is white regardless of the background color.

I tried this:

override var preferredStatusBarStyle : UIStatusBarStyle {
    return .lightContent
}

but doesn't work for me.

Amr
  • 286
  • 1
  • 2
  • 10
setropjp
  • 21
  • 3
  • Can you give more context to your issue? Like, do you want to change the color of the `statusBar` for the whole app? Or only in some `ViewController`s? And if only in some controllers, are they embedded in a `NavigationController` or not? Providing more details makes it easier for people here to help you. – Amr Sep 10 '21 at 13:21
  • Why is this tagged `macOS`? – EmilioPelaez Sep 10 '21 at 13:29
  • 1
    Use the debugger. Is your `preferredStatusBarStyle` override even being called? – matt Sep 10 '21 at 13:38
  • I have a button that opens a screen. On this screen I want the navigationBar to be white and the battery and time indicators to be black. – setropjp Sep 10 '21 at 14:50
  • I don't have just this screen. there are other screens before this one. Some are with navigationBar and some are not. – setropjp Sep 10 '21 at 14:52
  • Then, this will guide you on how to achieve what you want: https://stackoverflow.com/a/53340663/11974184 – Amr Sep 10 '21 at 15:17
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 17 '21 at 09:07

1 Answers1

-1

Create a new swift file called PostingController.swift

class PostingController: UIHostingController<ContentView> {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
}

Then change the line in the SceneDelegate.swift code file

window.rootViewController = UIHostingController(rootView: ContentView())

from follow lines

window.rootViewController = PostingController(rootView: ContentView())

The above answer is for SwiftUI

Sumit_VE
  • 429
  • 2
  • 12