添加按钮到ui导航控制器底栏 [英] adding buttons to ui navigation controller bottom bar

查看:118
本文介绍了添加按钮到ui导航控制器底栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下代码取消隐藏导航控制器底栏

I am able to unhide the navigation controller bottom bar by using the following code

[self.navigationController setToolbarHidden:NO];

但现在我想更改底栏的颜色,并在底栏添加按钮。任何人都可以帮助我如何做到这有没有任何委托方法?

But now I want to change the color of the bottom bar and also add buttons to that bottom bar. Can any one please help me how to do that is there any delegate methods for that?

推荐答案

在每个视图的viewDidLoad方法中您在导航控制器中显示的控制器,添加如下代码:

In the viewDidLoad method of each view controller that you are displaying within the navigation controller, add code such as the following:

//set up the toolbar
[self.navigationController setToolbarHidden:NO];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];  //for example

//set the toolbar buttons
 [self setToolbarItems:[NSArray arrayWithObjects:button1, button2, nil]];  

在这种情况下,button1和button2是视图控制器的IBOutlet属性,实际按钮定义为IB中的UIBarButtonItem(但不是IB中视图层次结构的一部分)。

In this case, button1 and button2 are IBOutlet properties of the view controller, with the actual buttons defined as UIBarButtonItem within IB (but not part of the view hierarchy within IB).

或者您可以使用代码创建按钮 - 如下所示:

Alternatively you can use code to create the buttons - like this:

UIBarButtonItem* button1 = [[[UIBarButtonItem alloc] initWithTitle:@"Button Text" style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)] autorelease];

这篇关于添加按钮到ui导航控制器底栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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