Change UINavigationBar Height

前端 未结 12 1483
囚心锁ツ
囚心锁ツ 2020-11-28 09:26

Can some one tell me how to change the navigation bar height?

Here is what i have so far:

CGFloat navBarHeight = 10;
self.navigationController.navi         


        
相关标签:
12条回答
  • 2020-11-28 09:48

    Following code won't affect other parameters in frame except height

     [self.navigationController.navigationBar setFrame:CGRectMake(self.navigationController.navigationBar.frame.origin.x, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, 150)];
    

    if you want change other parameters means, just edit the any one of the parameters....

    0 讨论(0)
  • 2020-11-28 09:49

    Try this code inside - (void)viewDidLayoutSubviews method,

    CGFloat navBarHeight = 10.0f;    
    CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, navBarHeight);
    [self.navigationController.navigationBar setFrame:frame];
    
    0 讨论(0)
  • 2020-11-28 09:51

    You can create a category class based on UINavigationBar like this

    .h file

    #import UIKit/UIKit.h    
    @interface UINavigationBar (myNave)
    - (CGSize)changeHeight:(CGSize)size;
    @end
    

    and .m file

    #import "UINavigationBar+customNav.h"
    @implementation UINavigationBar (customNav)
    - (CGSize)sizeThatFits:(CGSize)size {
        CGSize newSize = CGSizeMake(320,100);
        return newSize;
    }
    @end
    

    It works very nice.

    0 讨论(0)
  • 2020-11-28 09:53

    You should not change the height of the navigation bar. From Apple Programing Guide on View Controller:

    Customizing the Navigation Bar Appearance

    In a navigation interface, a navigation controller owns its UINavigationBar object and is responsible for managing it. It is not permissible to change the navigation bar object or modify its bounds, frame, or alpha values directly. However, there are a few properties that it is permissible to modify, including the following:

    ● barStyle property

    ● translucent property

    ● tintColor property

    (taken from Apple: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html)

    -- UPDATE -- IOS 7 --- still only the available properties can be changed but below is a great tutorial on how to achieve flexibility in the navigation bar http://www.appcoda.com/customize-navigation-status-bar-ios-7/

    0 讨论(0)
  • 2020-11-28 09:56

    Override -(void)viewWillAppear method in the viewController and Try the code below,

    - (void)viewWillAppear {
    
    UINavigationBar *navigationBar = [[self navigationController] navigationBar];
    CGRect frame = [navigationBar frame];
    frame.size.height = 82.0f;
    [navigationBar setFrame:frame];
    }
    
    0 讨论(0)
  • 2020-11-28 09:56

    Most Simple and Effective Solution is to add a category to navigation bar. (but maybe not the best solution)

    @interface UINavigationBar (CustomHeight)
    
    @end
    
    
    @implementation UINavigationBar (CustomHeight)
    
    - (CGSize)sizeThatFits:(CGSize)size {
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        return CGSizeMake(screenRect.size.width, kNavBarHeightNoStatus);
    }
    @end
    

    knavBarHeightNoStatus is the height of your navbar. We use UIScreen bounds because frame of UINavigationBar is wrong

    PS: Be careful, you can have some issues using it with a SideMenu

    0 讨论(0)
提交回复
热议问题