How to make the Navigation Bar of an UINavigationC

2019-01-26 17:39发布

Is there any way to make the default navigation bar of an UINavigationController display at the bottom instead of the top? I know that there is an UIToolbar that can be displayed at the bottom, but that one is specific to each view and does not carry the "back" button.

4条回答
萌系小妹纸
2楼-- · 2019-01-26 17:56

If you create your view using a NIB, then it is rather simple - select navigation bar in attributes->bottom bar. If not then you should access navigation bar directly and change its coordinates. In your view controller:

CGRect oldRect = self.navigationController.navigationBar.frame;
self.navigationController.navigationBar.frame = CGRectMake(x, y, oldRect.width, oldRect.height);

where x and y are coordinates to place your navigation bar.

查看更多
Lonely孤独者°
3楼-- · 2019-01-26 18:08

Here is the swift version:

var bottomNav = UINavigationBar(x: 0, y: view.frame.size.height - 20, w: view.frame.size.width, h: 44)
bottomNav.barStyle = UIBarStyle.Black
parentViewController?.view.addSubview(bottomNav)
查看更多
虎瘦雄心在
4楼-- · 2019-01-26 18:10

I think you can but i don't think it will approved by Apple

@implementation UINavigationBar (CustomBar)
- (void)drawRect:(CGRect)rect {
    self.frame = CGRectMake(0, 436, 320, 44);

}
查看更多
家丑人穷心不美
5楼-- · 2019-01-26 18:13

Try this :

bottomNav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0,  self.view.frame.size.height - 20, self.view.frame.size.width, 44.0)];  
bottomNav.barStyle = UIBarStyleBlackOpaque;  
[self.parentViewController.view addSubview:bottomNav];  
查看更多
登录 后发表回答