I have been attempting to set the statusbar in my SwiftUI app to light text as it has a dark background.
I found this solution on several sites but cannot get it to work.
HostingController.swift
import Foundation
import UIKit
import SwiftUI
class HostingController : UIHostingController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
This returns an error on the class declaration line Reference to generic type 'UIHostingController' requires arguments in <...>
with a suggested fix of Insert '<<#Content: View#>>'
. Applying said fix results in the error Use of undeclared type '<#Content: View#>'
You are then meant to change the window.rootViewController
in the SceneDelegate.swift
file.
SceneDelegate.swift
...
// Create the SwiftUI view that provides the window contents.
let contentView = Login()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = HostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
...
This throws an error on the window.rootViewController
line Argument passed to call that takes no arguments
Anyone got any ideas? Seems like a lot of bother just to set the status bar colour which I imagine would be a fairly common requirement.