Latest 1.1.1
Homepage https://github.com/wicharek/UINavigationBar-FixedHeightWhenStatusBarHidden
License MIT
Platforms ios 8.0
Authors ,

Version
License
Platform

Normally on iOS 7+ navigation bar height equals to 64 px, when status bar is shown. After it is hidden, the height is changed to 44 px by default.

This category adds property fixedHeightWhenStatusBarHidden to UINavigationBar class. If set to YES navigation bar will keep its size even if status bar was hidden.

This is especially useful in case of "drawer"-styled side panel, when you want status bar to be hidden when this panel is shown.

Installation

Manual:

Copy source files from UINavigationBar-FixedHeightWhenStatusBarHidden folder to your Xcode project.

CocoaPods:

UINavigationBar-FixedHeightWhenStatusBarHidden is available through CocoaPods. To install
it, add the following line to your Podfile:

pod 'UINavigationBar-FixedHeightWhenStatusBarHidden'

How to Use

Add #import "UINavigationBar+FixedHeightWhenStatusBarHidden.h".

Enable fixed height with:

self.navigationController.navigationBar.fixedHeightWhenStatusBarHidden = YES;

On iOS 11+ you should also set correct additional safe area insets on each view controller presented inside UINavigationController with fixed height enabled. This can be done by overriding viewWillLayoutSubviews of UIViewController. Then you can install the required insets automatically:

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    [self.navigationController.navigationBar setAdditionalSafeAreaInsetsForViewController:self];    
}

Or in case you need to customize insets, use [UINavigationBar additionalSafeAreaInsets] selector to get insets required for fixed height to work and modify them according to your needs:

- (void)viewWillLayoutSubviews {
   [super viewWillLayoutSubviews];

    if (@available(iOS 11.0, *)) {
        UIEdgeInsets navigationBarSafeAreaInsets = [self.navigationController.navigationBar additionalSafeAreaInsets];
        self.additionalSafeAreaInsets = UIEdgeInsetsMake(navigationBarSafeAreaInsets.top + 20, 0, 0, 0);
    }
}

License

UINavigationBar-FixedHeightWhenStatusBarHidden is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "UINavigationBar-FixedHeightWhenStatusBarHidden",
    "version": "1.1.1",
    "summary": "This pod adds property to UINavigationBar class to keep its size even if status bar was hidden.",
    "description": "Normally on iOS 7+ navigation bar height equals to 64 px, when status bar is shown. After it is hidden, the height is changed to 44 px by default.nThis category adds property `fixedHeightWhenStatusBarHidden` to UINavigationBar class. If set to YES navigation bar will keep its size even if status bar was hidden.nThis is especially useful in case of "drawer"-styled side panel, when you want status bar to be hidden when this panel is shown.",
    "homepage": "https://github.com/wicharek/UINavigationBar-FixedHeightWhenStatusBarHidden",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Vitaliy Ivanov": "[email protected]",
        "Viktor Naryshkin": "[email protected]"
    },
    "source": {
        "git": "https://github.com/wicharek/UINavigationBar-FixedHeightWhenStatusBarHidden.git",
        "tag": "1.1.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "UINavigationBar-FixedHeightWhenStatusBarHidden/*"
}

Pin It on Pinterest

Share This