如何向NavigationBar添加多个按钮? [英] How to add multiple buttons to a NavigationBar?

查看:103
本文介绍了如何向NavigationBar添加多个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我已经成功地添加了一个rightBarButtonItem来调用自定义选择器(从UIViewController调用),如下:

Ok, so I've successfully added a rightBarButtonItem to call a custom selector (called from a UIViewController), as follows:

 UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];

 [infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];

 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];

可以使右侧栏按钮项实际上是几个不同的按钮

Is it possible to make the "right bar button item" actually be several distinct buttons (and thus remove the title text from the navigation bar)?

我正在寻找获得更多屏幕空间的方法,这似乎是一个合理的选择...虽然任何其他建议会赞赏(也许我应该减小标签栏的大小,我在底部使用...)

I'm searching for ways to get more screen real estate, and this seems like a logical choice... although any other suggestions would be appreciated (maybe i should reduce the size of the tab bar i use at the bottom...)

推荐答案

UIBarButtonItem *addAcc = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Add"                                            
                               style:UIBarButtonItemStylePlain 
                               target:self 
                               action:@selector(addNewAcc)];

UIBarButtonItem *delAcc = [[UIBarButtonItem alloc] 
          initWithTitle:@"Del"                                            
          style:UIBarButtonItemStylePlain 
          target:self 
          action:@selector(DeleteButtonAction)];

NSArray *arrBtns = [[NSArray alloc]initWithObjects:addAcc,delAcc, nil];
self.navigationItem.rightBarButtonItems = arrBtns;

这篇关于如何向NavigationBar添加多个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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