如何更改导航栏高度
我看到了一个改变导航栏高度的解决方案。 但没有什么对我有用。 现在我的应用程序有一个与导航控制器连接的视图控制器。 我还没有在我的项目中实现任何其他代码。 在开始我的项目之前,我需要更改导航栏的高度。
编辑:
。H:
- (CGSize)sizeThatFits:(CGSize)size ;
.M:
@implementation UINavigationBar (customNav) - (CGSize)sizeThatFits:(CGSize)size { CGSize newSize = CGSizeMake(370,40); return newSize; } @end
UIView *NavView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 , [UIScreen mainScreen].bounds.size.width , 44)]; NavView.backgroundColor = [UIColor clearColor]; NavView.userInteractionEnabled = YES; [self.navigationController.navigationBar addSubview:NavView]; UIButton *DateBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, 90, 30)]; DateBtn.backgroundColor = [UIColor clearColor]; [DateBtn setTitle:@"Jan 05" forState:UIControlStateNormal]; DateBtn.titleLabel.font = [UIFont fontWithName:BrushScriptStd size:18]; [DateBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [NavView addSubview:DateBtn];
您无法更改UINavigation高度,但可以在UINavigation栏上添加自定义视图
解决此问题的非常简单的方法是可以从StoryBoard或Code创建view
。
并将视图添加到viewController。
您必须从项目中禁用默认导航栏。 你也可以通过Storyboard来做到这一点。 选择导航栏并将状态栏更改为none:
如果你想通过代码然后在你的didFinishLaunching
wirte这段代码:
UIStoryboard *tStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; RootVC* RootVCObj = [tStoryBoard instantiateViewControllerWithIdentifier:@"RootVC"]; UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:RootVCObj]; navC.navigationBarHidden = YES;
在此之后添加尽可能多的按钮到您的视图
这方面的主要缺点是您必须为您当前拥有的所有屏幕制作自定义视图