Swift Package Index


A library that helps to manage the navigation bar style. It helps to remember bar attributes between different VCs and keep the transition smooth.


  • The latest stable release is 1.0.0. Released over 1 year ago.
  • The last commit to master was over 1 year ago.

Swift Version Compatibility

  • 1.0.0
    5.3
    5.2
    5.1
    5.0
    4.2
  • master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 1.0.0 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

Build Status

NavigationBarHelper

A library that helps to manage the navigation bar style. It helps to remember bar attributes between different VCs and keep the transition smooth.

alt tag

Usage

When your app finishes launch, call the function below to start up the helper.

NavigationBarHelper.load()

swizzle UIViewController.viewSafeAreaInsetsDidChange

swizzle UIViewController.viewWillLayoutSubviews

swizzle UIViewController.viewWillAppear(_:)

UINavigationBar.hitTest(_:with:)

For a viewController, use the function below to modify the navigation bar.

override func viewDidLoad() {
    super.viewDidLoad()
    barBackgroundHelper.perform {
        //Codes for navigation bar update.
        //e.g. $0.tintColor = UIColor.white
    }
}

After calling the function above, any attribute (background image/tintColor/barTintColor/barStyle etc) will be remembered by the library. It will create a mirror background view of the navigation bar (auto managed) and clear the bar background (to provide a smooth transition). Any change to the navigation bar background (background image/barTintColor/barStyle/shadowImage) in the closure will be syncronized with the mirror view.

Protocol NavigationBarHelperDelegate

  • willRestore(backgroundAttr: inout NavigationBarHelper.BackgroundAttr)

Called before the mirror view capturing the bar's background attribute. Modify the backgroundAttr if it is not your appetite.

  • didRestore(backgroundAttr: NavigationBarHelper.BackgroundAttr)

Called after the mirror view capturing the bar's background attribute. It is the best time for you to do additional change to the bar's background attr. After this function is called, the mirror background view will synchronize with the bar's background.

  • willRestore(foregroundAttr: inout NavigationBarHelper.ForegroundAttr)

Called before the navigation bar's foreground attribute being restored, especially when the viewController's appearing. Modify the foregroundAttr if it is not your appetite.

  • didRestore(foregroundAttr: NavigationBarHelper.ForegroundAttr)

Called after the navigation bar's foreground attribute being restored, especially when the viewController's appearing. Do additional change if you have modified the navigation bar out of the performNavigationBarUpdates scope.(e.g, you have set the bar tint color according to scrollview offset).

License

(MIT license)