简体   繁体   English

添加按钮到ui导航控制器底栏

[英]adding buttons to ui navigation controller bottom bar

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? 任何人都可以帮助我如何做到这一点是否有任何委托方法?

In the viewDidLoad method of each view controller that you are displaying within the navigation controller, add code such as the following: 在导航控制器中显示的每个视图控制器的viewDidLoad方法中,添加如下代码:

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

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). 在这种情况下,button1和button2是视图控制器的IBOutlet属性,实际按钮在IB内定义为UIBarButtonItem(但不是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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM