how do I change the UINavigationBar's height

萝らか妹 提交于 2019-12-10 10:56:49

问题


This issue has crippled me for over a day. I need to modify the UINavigationBar's height.

The UINavigationController is created in the AppDelegate like so.

self.navigationController = [[UINavigationController alloc] initWithRootViewController:mainController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];

The height of the navbar WILL change and stick if I add [self.navigationController.navigationBar setFrame:newFrame] to viewDidAppear like the code below.

- (void)viewWilAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    CGRect newFrame = CGRectMake(0, 0, 320, 100);
    [self.navigationController.navigationBar setFrame:newFrame]
}

HOWEVER, if I do it this way, you can actually see the frame snapping from the original 44px to a 100px height in the split second that the view loads, which is very annoying.

I've tried adding the [navBar setFrame:] to viewDidload, viewWillAppear of the rootViewController and also the AppDelegate just after I initiate the UINavigationController. None of these work.

Just so you know, I've overridden the drawRect:(CGRect)rect method in a UINavigationBar category to make the background color solid black using the code below but I don't think that has something to do with the problem.

[[UIColor blackColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);

Does anyone know the best way to do this?


回答1:


"Use a toolbar instead of a navigation bar if you need to offer a larger set of controls, or you do not need to enable navigation." - From the iOS Human Interface Guidelines under Navigation Bar / Guidelines.



来源:https://stackoverflow.com/questions/6590691/how-do-i-change-the-uinavigationbars-height

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