ios – How to override UIStatusBarStyle of UIAlertController


I have a UIViewController in a UINavigationController where I want to force the status bar colour to be white at all times. I’ve achieved this by subclassing UINavigationController:

class CustomNavigationController: UINavigationController {
    override var childForStatusBarStyle: UIViewController? {
        return visibleViewController
    }
}

Then in the ViewController, setting:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

That is fine. In the same UIViewController, I present an action sheet UIAlertController. When this appears, it changes the status bar’s style back to .default (so black text and illegible).

I’ve tried subclassing it and overriding preferredStatusBarStyle, but it doesn’t seem to make any difference, nor did calling setNeedsStatusBarAppearanceUpdate().

Where do I need to be setting the style for the action sheet?

There are lots of varying questions about UIStatusBarStyle admittedly but many are out of date or don’t deal specifically with the issue here.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img