[英]adding buttons to ui navigation controller bottom bar
我可以使用以下代碼取消隱藏導航控制器底欄
[self.navigationController setToolbarHidden:NO];
但現在我想改變底欄的顏色,並在底欄上添加按鈕。 任何人都可以幫助我如何做到這一點是否有任何委托方法?
在導航控制器中顯示的每個視圖控制器的viewDidLoad方法中,添加如下代碼:
//set up the toolbar
[self.navigationController setToolbarHidden:NO];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque]; //for example
//set the toolbar buttons
[self setToolbarItems:[NSArray arrayWithObjects:button1, button2, nil]];
在這種情況下,button1和button2是視圖控制器的IBOutlet屬性,實際按鈕在IB內定義為UIBarButtonItem(但不是IB中視圖層次結構的一部分)。
或者,您可以使用代碼創建按鈕 - 如下所示:
UIBarButtonItem* button1 = [[[UIBarButtonItem alloc] initWithTitle:@"Button Text" style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)] autorelease];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.