我如何添加左邊的barButton
或旁邊的按鈕rightbarButton
, 我的意思是我需要在標題欄上有2個以上的按鈕是可能的嗎?如何添加左邊的酒吧控制器或右邊的酒吧控制器旁邊的按鈕
thanx提前
我如何添加左邊的barButton
或旁邊的按鈕rightbarButton
, 我的意思是我需要在標題欄上有2個以上的按鈕是可能的嗎?如何添加左邊的酒吧控制器或右邊的酒吧控制器旁邊的按鈕
thanx提前
由於從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發佈
您可以使用視圖具有兩個按鈕在你左邊巴頓 -
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftBtnsView];
我建議使用UISegmentedControl
來保存所有按鈕,並使用 [[UIButton alloc] initWithCustomView:]
來顯示段控制。
下面是你如何去做這件事的一個例子。我使用的是隨此示例的頂部導航欄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;
}
你可以做這樣的事情,有一些所謂的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];
我認爲你需要像這樣
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];
這不是問題 – artud2000 2014-02-04 20:40:54