2011-05-13 90 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]; 
相關問題