How do I resize height of UINavigationBar while allowing to set root view controller?

强颜欢笑 提交于 2019-12-12 01:21:44

问题


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.



来源:https://stackoverflow.com/questions/31217984/how-do-i-resize-height-of-uinavigationbar-while-allowing-to-set-root-view-contro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!