如何向NavigationBar添加多个按钮? [重复]

时间:2023-01-16 19:19:25

This question already has an answer here:

这个问题在这里已有答案:

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

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

 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...)

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

2 个解决方案

#1


21  

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;

#2


0  

Well, you could use a UISegmentedControl with the bar style. Or you could add a generic UIView and add whatever buttons you want.

好吧,你可以使用带有条形样式的UISegmentedControl。或者你可以添加一个通用的UIView并添加你想要的任何按钮。

#1


21  

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;

#2


0  

Well, you could use a UISegmentedControl with the bar style. Or you could add a generic UIView and add whatever buttons you want.

好吧,你可以使用带有条形样式的UISegmentedControl。或者你可以添加一个通用的UIView并添加你想要的任何按钮。