Add a Nav Bar Bottom ToolBar

PDF for offline use
Sample Code:
Related SDKs:

Let us know how you feel about this

Translation Quality


0/250

This recipe illustrates how to add a toolbar to the bottom of a view.

Recipe

To add a toolbar to the bottom of the view:

  1. Create a toolbar by setting an array of UIBarButtonItems:
this.SetToolbarItems( new UIBarButtonItem[] {
    new UIBarButtonItem(UIBarButtonSystemItem.Refresh, (s,e) => {
        Console.WriteLine("Refresh clicked");
    })
    , new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace) { Width = 50 }
    , new UIBarButtonItem(UIBarButtonSystemItem.Pause, (s,e) => {
        Console.WriteLine ("Pause clicked");
    })
}, false);
  1. Finally, to show the Toolbar:
this.NavigationController.ToolbarHidden = false;

Additional Information

If you are creating a complex toolbar with many items, it might be easier to construct the buttons separately:

var refreshButton = new UIBarButtonItem(UIBarButtonSystemItem.Refresh, (s, e) => {
    Console.WriteLine("Refresh clicked");
})

var pauseButton = new UIBarButtonItem(UIBarButtonSystemItem.Pause, (s, e) => {
    Console.WriteLine("Pause clicked");
})

var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace) { Width = 50 };

this.SetToolbarItems( new UIBarButtonItem[] {
    refreshButton, spacer, pauseButton
}, false);

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.