1, first will show toolbar, add code in viewdidload let toolbar display, the code is as follows:
[OBJC]View Plaincopyprint? < param name= "wmode" value= "Transparent" >
- [self. Navigationcontroller Settoolbarhidden:NO animated:YES]
Display as:
2, add Uibarbuttonitem on the toolbar
Create a few uibarbuttonitem and add it as an array to the toolbar
[OBJC]View Plaincopyprint? < param name= "wmode" value= "Transparent" >
- Uibarbuttonitem *camera=[[uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera target:self Action:@selector (Clicktoolbarbutton)];
- [Camera setwidth:80];
- uibarbuttonitem *refresh=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem: Uibarbuttonsystemitemrefresh target:self Action:@selector (Clicktoolbarbutton)];
- [Refresh setwidth:80];
- uibarbuttonitem *reply=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem: Uibarbuttonsystemitemreply target:self Action:@selector (Clicktoolbarbutton)];
- [Reply setwidth:80];
- uibarbuttonitem *compose=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem: Uibarbuttonsystemitemcompose target:self Action:@selector (Clicktoolbarbutton)];
- [Compose setwidth:80];
- uibarbuttonitem *splitspace=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem: Uibarbuttonsystemitemflexiblespace target: nil action: nil];
- [self settoolbaritems:[nsarray arraywithobjects:splitspace,camera,splitspace,refresh,splitspace, Reply,splitspace,compose,splitspace, nil Nil]];
Define the Click event with the following code:
[OBJC]View Plaincopyprint?
- -(void) clicktoolbarbutton{
- NSLog (@ "you clicked!");
- }
The final run is as follows:
Description: Using [Self.navigationcontroller Settoolbaritems:[nsarray Arraywithobjects:splitspace,camera,splitspace,refresh, Splitspace,reply,splitspace,compose,splitspace, nil] animated:yes]; adding is not working.
3, custom toolbar, first create a new page, in the header file declaration Uitoolbar *toolbar;
To implement the custom toolbar in the Viewdidload method in the implementation file, the implementation code is as follows:
[OBJC]View Plaincopyprint?
- -(void) Viewdidload
- [Super Viewdidload];
- [self. Navigationcontroller Settoolbarhidden:Yes animated:Yes];
- //Custom UIView
- UIButton *btn=[uibutton Buttonwithtype:uibuttontypecontactadd];
- [Btn addTarget:self action: nil forcontrolevents:uicontroleventtouchupinside];
- uibarbuttonitem *firstbutton=[[uibarbuttonitem alloc] initwithcustomview:btn];
- [Firstbutton setwidth:120];
- //System comes with a view
- uibarbuttonitem *addbutton=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem: Uibarbuttonsystemitembookmarks target:self Action: nil];
- toolbar=[[uitoolbar alloc] Initwithframe:cgrectmake (0, self .view.frame.size.height-toolbar.frame.size< Span class= "xcodeconstants" >.height-44, self.view.frame.size.width, 4 4)];
- [Toolbar Setbarstyle:uibarstyledefault];
- Toolbar. Autoresizingmask=uiviewautoresizingflexibletopmargin;
- [Toolbar Setitems:[nsarray Arraywithobjects:addbutton,firstbutton,Nil]];
- [self. View Addsubview:toolbar];
- //do any additional setup after loading the view from its nib.
After running the following interface:
IOS Navigationcontroller Toolbar Learning notes