简体   繁体   中英

adding buttons to ui navigation controller bottom bar

I am able to unhide the navigation controller bottom bar by using the following code

[self.navigationController setToolbarHidden:NO];

But now I want to change the color of the bottom bar and also add buttons to that bottom bar. Can any one please help me how to do that is there any delegate methods for that?

In the viewDidLoad method of each view controller that you are displaying within the navigation controller, add code such as the following:

//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]];  

In this case, button1 and button2 are IBOutlet properties of the view controller, with the actual buttons defined as UIBarButtonItem within IB (but not part of the view hierarchy within IB).

Alternatively you can use code to create the buttons - like this:

UIBarButtonItem* button1 = [[[UIBarButtonItem alloc] initWithTitle:@"Button Text" style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)] autorelease];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM