How do I resize height of UINavigationBar while al

2019-08-30 03:13发布

问题:

I want to resize height of UINavigationBar I came across few questions previously asked here, but I believe this is quite different then those.

Found that, I've to make subclass of UINavigationBar and where I should update height of it. But then to use that subclassed navigation bar I've to use below method of UINavigationController.

Here it is:

- (id) initWithNavigationBarClass:(nullable Class)navigationBarClass 
toolbarClass:(nullable Class)toolbarClass;

if I used this to set my subclassed navigation bar, then how do I set its rootViewController using below method:

- (id) initWithRootViewController:(UIViewController *)rootViewController;

Is there any other way that, I can achieve my goal of resized navigationbar height and also I should set a root view controller to it?

回答1:

Subclassing UINavigationBar do the trick !

#import <UIKit/UIKit.h>

@interface BaseNavigationBar : UINavigationBar

@end

@implementation BaseNavigationBar
- (CGSize)sizeThatFits:(CGSize)size {return CGSizeMake(self.superview.bounds.size.width, 24.f);}
@end


回答2:

In the documentation they say that the property viewControllersreturns an array that at index 0 contains the root view controller.
I think that if you pass at this property an array of VCs the object at index zero will be taken as the root. Or just a one element array.