The Uitoolbar exists in the Uinavigationcontroller navigation bar controller and is hidden by default, and the Toolbarhidden property of the Uinavigationcontroller is set to display Uitoolbar.
first, the setting of Uitoolbar1, in the ROOTVIEWCONTROLLER.MViewdidload methodAdd code to the
[Self.navigationcontroller Settoolbarhidden:no Animated:yes];
Show Bottom Toolbar
2. Set Uitoolbar property: (used after iOS7)
// set the trace color [Self.navigationController.toolbar Setbartintcolor:[uicolor Greencolor];
// set a background picture [Self.navigationController.toolbar setbackgroundimage:[uiimage imagenamed:@ "40-15092z94009 "] fortoolbarposition:uibarpositionbottom Barmetrics:uibarmetricsdefault];
3. Create Uibarbuttonitem
Uibarbuttonitem *left = [[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemreply target: Nil Action:nil]; *center = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcompose target:nil action: Nil]; *right = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:nil Action:nil]; // blank uibarbuttonitem *blank = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemflexiblespace Target:nil Action:nil];
4. add Uibarbuttonitem for Uitoolbar
1) Create an array itemsarray;
2) Add Uibarbuttonitem on the array;
3) pass Itemsarray to Uitoolbar;
Nsarray *itemsarray = @[left, blank, center, blank, right]; [Self settoolbaritems:itemsarray];
Second, custom Uitoolbar
1. Hidden System toolbar: added in Rootviewcontroller.m viewdidload method
[Self.navigationcontroller Settoolbarhidden:yes Animated:yes];
Add the new toolbar to the view, and set an item for Toobar,
Uibarbuttonitem*one = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@""] Style:uibarbuttonitemstyleplain Target:nil Action:nil]; Uibarbuttonitem*two = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@""] Style:uibarbuttonitemstyleplain Target:nil Action:nil]; Nsarray*buttons =@[one,two]; ToolBar= [[Uitoolbar alloc] initWithFrame: (cgrect) {0.0, Self.view.frame.size.height-toolbar.frame.size.height-44.0, Self.view.frame.size.width,44.0}]; Toolbar.autoresizingmask=Uiviewautoresizingflexibletopmargin; [ToolBar Setbarstyle:uibarstyledefault]; [ToolBar setitems:buttons]; [Self.view Addsubview:toolbar];
Uinavigationcontroller's introduction to this place is over.
iOS Basics (12) Use of--uinavgationcontroller (iii) ToolBar