StatusBarStyle is an iOS library that makes it easy to style the status bar on SwiftUI views.
How it works
This library is inspired by SwiftUI-Introspect. It also works by adding StatusBarStylingView to the view hierarchy, and swizzles childForStatusBarStyle, childForStatusBarHidden getters of UIHostingController to refer to style of the status bar set in it. So it may not work as intended in projects that are already swizzling the getters.
StatusBarStyling: StatusBarStyling provides setup() static function to be called when app is initialized and statusBar(style:hidden:) function that can be used as an extension of SwiftUI.View.
NavigationStatusBarStyling: NavigationStatusBarStyling also provides setup() static function to be called when the app is initialized. The difference with StatusBarStyling is that it swizzles not only UIHostingController, but also childForStatusBarStyle, childForStatusBarHidden getters of UINavigationController. It is recommended to use this library unless you specifically override the corresponding properties. If you are already deep using UINavigationController, you can optionally use StatusBarStyling.
StatusBarStyling
StatusBarStyle is an iOS library that makes it easy to style the status bar on SwiftUI views.
How it works
This library is inspired by SwiftUI-Introspect. It also works by adding
StatusBarStylingView
to the view hierarchy, and swizzleschildForStatusBarStyle
,childForStatusBarHidden
getters ofUIHostingController
to refer to style of the status bar set in it. So it may not work as intended in projects that are already swizzling the getters.StatusBarStyling: StatusBarStyling provides
setup()
static function to be called when app is initialized andstatusBar(style:hidden:)
function that can be used as an extension ofSwiftUI.View
.NavigationStatusBarStyling: NavigationStatusBarStyling also provides
setup()
static function to be called when the app is initialized. The difference with StatusBarStyling is that it swizzles not onlyUIHostingController
, but alsochildForStatusBarStyle
,childForStatusBarHidden
getters ofUINavigationController
. It is recommended to use this library unless you specifically override the corresponding properties. If you are already deep usingUINavigationController
, you can optionally use StatusBarStyling.Table of Contents
Requirements
StatusBarStyling codebase supports iOS and requires Xcode 14.0 or newer. This library has a Base SDK version of 14.0.
Usage
First of all, it performs based on swizzling, you must be set it up when your app is initialized like:
And use
statusBar(style:hidden:)
function in SwiftUI views like:In general, the innermost status bar style in the view hierarchy is applied like:
Examples
There are 2 example projects(StoryboardBased, SwiftUIBased) in the repository, so refer to them when using them in your project.
StoryboardBased
SwiftUIBased
License
This project is made available under the terms of a MIT license. See the LICENSE file.