[ad_1]
Hello there 🙂 I am making an attempt to set the standing bar’s textual content shade to gentle or darkish on app load, I am utilizing SwiftUI not UIKit so I haven’t got any fancy ViewControllers, this is what I’ve tried to this point:
In my Test_applicationApp file:
import SwiftUI
@major
struct Test_applicationApp: App {
var physique: some Scene {
WindowGroup {
ContentView()
}
}
}
extension UIApplication {
func switchHostingController() -> Void {
home windows.first?.rootViewController = DarkHostingController(rootView: ContentView())
}
}
class DarkHostingController<ContentView>: UIHostingController<ContentView> the place ContentView : View {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
ContentView:
import SwiftUI
struct ContentView: View {
init() {
UIApplication.shared.switchHostingController()
}
var physique: some View {
ZStack {
......
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
What occurs with that is that if I am in gentle theme, the textual content shade is darkish like so:
(That is on a iPhone 8, model 15.6.1)
Does anybody understand how to do that? Any assist in any respect could be actually appreciated! Additionally in case you’re confused or want any extra particulars on this questions be happy to hit me up, I did not precisely write this query completely because it’s getting late and I needed to kind it out in a rush XD
Thanks!
[ad_2]

