StatusBarStyling

1.0.0

StatusBarStyling is an iOS library that makes it easy to style the status bar on SwiftUI views.
PRNDcompany/StatusBarStyling

What's New

v1.0.0

2023-05-17T08:00:23Z

🎉 The first stable release

StatusBarStyling codebase supports iOS and requires Xcode 14.0 or newer. This library has a Base SDK version of 14.0.

StatusBarStyling

License Version Swift Versions OS's Xcode 14.0+ SPM

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 childForStatusBarStylechildForStatusBarHidden 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.

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:

import NavigationStatusBarStyling // or StatusBarStyling

final class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        NavigationStatusBarStyling.setup() // or StatusBarStyling.setup()
        return true
    }
}

And use statusBar(style:hidden:) function in SwiftUI views like:

import StatusBarStyling

struct ContentView: View {
    var body: some View {
        Text("ContentView")
            .statusBar(style: .lightContent, hidden: false)
    }
}

In general, the innermost status bar style in the view hierarchy is applied like:

import StatusBarStyling

struct ContentView: View {
    var body: some View {
        VStack {
            Text("1")
            
            VStack {
                Text("2")
                
                VStack {
                    Text("3")
                    
                    VStack {
                        Text("4")
                            .statusBar(style: .darkContent)
                    }
                }
            }
        }
        .statusBar(style: .lightContent)
    }
}

In general, the innermost status bar style in the view hierarchy is applied.

Examples

There are 2 example projects(StoryboardBased, SwiftUIBased) in the repository, so refer to them when using them in your project.

StoryboardBased

StoryboardBased

SwiftUIBased

SwiftUIBased

License

This project is made available under the terms of a MIT license. See the LICENSE file.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu May 25 2023 10:17:23 GMT-0500 (GMT-05:00)