如何改变导航栏的高度

5

我看到了一种解决方法可以改变导航栏的高度。但是对我来说都没有起作用。现在我的应用程序有一个视图控制器连接着一个导航控制器。在我的项目中,我还没有实现任何其他代码。在开始我的项目之前,我需要改变我的导航栏高度。

编辑后:

.h:

- (CGSize)sizeThatFits:(CGSize)size ;

.m:

@implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = CGSizeMake(370,40);
    return newSize;
}
@end

请看这个链接:https://dev59.com/m4Tba4cB1Zd3GeqP30rh#26381417 - Kirit Modi
请问如何设置 iPhone 导航栏的高度? - darshan
https://dev59.com/SHNA5IYBdhLWcg3wmfO5 - Rahul
@RahulMishra 我尝试了高度,它可以工作,但是我的宽度在所有屏幕上都不同。 - david
这怎么可能?你在使用自动布局吗? - Rahul
显示剩余2条评论
3个回答

2
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];

在添加解决方案时,我应该连接导航控制器还是我的视图控制器? - david
是的,您需要连接导航控制器。 - Jugal K Balara
请看我更新的帖子,我已经尝试过了,但是在所有屏幕上只有宽度不同。 - david
你需要另一种解决方案来隐藏控制器上的导航栏,然后添加自定义视图。 - Jugal K Balara
只有添加了一个按钮,导航栏的高度没有改变...我只是复制和粘贴了 - david
显示剩余3条评论

0

你不能改变UINavigation的高度,但是你可以在UINavigation栏上添加自定义视图


你能为我提供一些代码解释吗?因为我有很多屏幕都连接到导航栏,所以我该怎样添加自定义视图以适用于所有屏幕?此外我还有一些标题和导航栏按钮项。 - david
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]; - Jugal K Balara

0
非常简单的解决方案是,您可以从StoryBoard或代码中创建view。将视图添加到您的viewController中。
您必须禁用项目中的默认导航栏。 您也可以通过Storyboard完成此操作。选择您的导航栏并将状态栏更改为none:

enter image description here

如果您想通过代码实现,那么请在您的didFinishLaunching方法中编写以下代码:

UIStoryboard *tStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    RootVC* RootVCObj = [tStoryBoard instantiateViewControllerWithIdentifier:@"RootVC"];

    UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:RootVCObj];
    navC.navigationBarHidden = YES;

接下来,您可以在视图中添加任意数量的按钮

这种方法的主要缺点是您必须为当前所有屏幕制作自定义视图


请问有什么解决方案吗?https://stackoverflow.com/questions/46251141/swipe-left-or-right-to-load-the-view-controller-with-the-collection-view-cell-hi - david

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接