如何在允许设置根视图控制器的同时调整 UINavigationBar 的高度? [英] How do I resize height of UINavigationBar while allowing to set root view controller?

查看:43
本文介绍了如何在允许设置根视图控制器的同时调整 UINavigationBar 的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调整 UINavigationBar 的高度我遇到了一些之前在这里问过的问题,但我相信这与那些完全不同.

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

发现,我必须创建 UINavigationBar 的子类以及我应该在哪里更新它的高度.但是要使用该子类导航栏,我必须使用 UINavigationController 的以下方法.

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.

这是:

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

如果我用它来设置我的子类导航栏,那么我如何使用以下方法设置它的 rootViewController:

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?

推荐答案

Subclassing UINavigationBar 搞定!

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

这篇关于如何在允许设置根视图控制器的同时调整 UINavigationBar 的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆