Code Monkey home page Code Monkey logo

whuxujiyuan / uinavigationbar-fixedheightwhenstatusbarhidden Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wicharek/uinavigationbar-fixedheightwhenstatusbarhidden

0.0 1.0 1.0 14 KB

Category for iOS 7 navigation bar, allowing it to keep its height even if status bar was hidden

Home Page: https://www.factorialcomplexity.com/blog/2014/08/05/fixed-height-navigation-bar-on-ios7.html

License: MIT License

Ruby 21.28% Objective-C 78.72%

uinavigationbar-fixedheightwhenstatusbarhidden's Introduction

UINavigationBar-FixedHeightWhenStatusBarHidden

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.