2011-05-13 134 views

回答

0

由于从this blog post得出:

认为一个工具栏为您的容器,而不是 的UIView的对象。由于UIToolBar基于UIView,因此可以使用上述技巧将 添加到导航栏右侧的 。该 下面的代码演示了如何添加 两个标准按键向右 侧:

// create a toolbar to have two buttons in the right 
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)]; 

// create the array to hold the buttons, which then gets added to the toolbar 
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3]; 

// create a standard "add" button 
UIBarButtonItem* bi = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL]; 
bi.style = UIBarButtonItemStyleBordered; 
[buttons addObject:bi]; 
[bi release]; 

// create a spacer 
bi = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 
[buttons addObject:bi]; 
[bi release]; 

// create a standard "refresh" button 
bi = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)]; 
bi.style = UIBarButtonItemStyleBordered; 
[buttons addObject:bi]; 
[bi release]; 

// stick the buttons in the toolbar 
[tools setItems:buttons animated:NO]; 

[buttons release]; 

// and put the toolbar in the nav bar 
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
[tools release]; 

同时检查SO发布

Adding buttons to navigation bar

0

您可以使用视图具有两个按钮在你左边巴顿 -

UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftBtnsView]; 
0

我建议使用UISegmentedControl来保存所有按钮,并使用 [[UIButton alloc] initWithCustomView:]来显示段控制。

0

下面是你如何去做这件事的一个例子。我使用的是随此示例的顶部导航栏MasterDetailView模板:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] init]; 
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] init]; 
    leftButton.title = @"Left button"; 
    rightButton.title = @"right button"; 
    self.navigationItem.leftBarButtonItem = leftButton; 
    self.navigationItem.rightBarButtonItem = rightButton; 
} 
+0

这不是问题 – artud2000 2014-02-04 20:40:54

0

你可以做这样的事情,有一些所谓的UINavigationItem.rightBarButtonItems

的UIBarButtonItem * settingsButton = [[的UIBarButtonItem [] UIImageNameName:@“xxx.png”] style:UIBarButtonItemStyleDone target:self action:@selector(something)];

的UIBarButtonItem *菜单按钮= [[ALLOC的UIBarButtonItem] initWithImage:[UIImage的imageNamed:@ “xxx.png”] 样式:UIBarButtonItemStyleDone目标:自 动作:@selector(东西)];

self.navigationItem.rightBarButtonItems = @ [settingsButton,menuButton];

0

我认为你需要像这样

UIBarButtonItem *firstButton = [[UIBarButtonItem alloc] initWithTitle:@"First" style:UIBarButtonItemStyleBordered target:self action:nil]; 
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:@"Second" style:UIBarButtonItemStyleBordered target:self action:nil]; 
[email protected][firstButton, secondButton]; 

它将在左侧导航栏中的添加两个栏按钮的项目。你可以用同样的方式使它在右侧

[email protected][firstButton, secondButton];