IOS Navigationcontroller Toolbar Learning Notes

Source: Internet
Author: User

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" >
    1. [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" >
  1. Uibarbuttonitem *camera=[[uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera  target:self Action:@selector (Clicktoolbarbutton)];
  2. [Camera setwidth:80];
  3. uibarbuttonitem *refresh=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem:  Uibarbuttonsystemitemrefresh target:self Action:@selector (Clicktoolbarbutton)];
  4. [Refresh setwidth:80];
  5. uibarbuttonitem *reply=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem:  Uibarbuttonsystemitemreply target:self Action:@selector (Clicktoolbarbutton)];
  6. [Reply setwidth:80];
  7. uibarbuttonitem *compose=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem:  Uibarbuttonsystemitemcompose target:self Action:@selector (Clicktoolbarbutton)];
  8. [Compose setwidth:80];
  9. uibarbuttonitem *splitspace=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem:  Uibarbuttonsystemitemflexiblespace target: nil action: nil];
  10. [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?
    1. -(void) clicktoolbarbutton{
    2. NSLog (@ "you clicked!");
    3. }

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?
  1. -(void) Viewdidload
  2. [Super Viewdidload];
  3. [self. Navigationcontroller Settoolbarhidden:Yes animated:Yes];
  4. //Custom UIView
  5. UIButton *btn=[uibutton Buttonwithtype:uibuttontypecontactadd];
  6. [Btn addTarget:self action: nil forcontrolevents:uicontroleventtouchupinside];
  7. uibarbuttonitem *firstbutton=[[uibarbuttonitem alloc] initwithcustomview:btn];
  8. [Firstbutton setwidth:120];
  9. //System comes with a view
  10. uibarbuttonitem *addbutton=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem:  Uibarbuttonsystemitembookmarks target:self Action: nil];
  11.    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)];   
  12. [Toolbar Setbarstyle:uibarstyledefault];
  13. Toolbar. Autoresizingmask=uiviewautoresizingflexibletopmargin;
  14. [Toolbar Setitems:[nsarray Arraywithobjects:addbutton,firstbutton,Nil]];
  15. [self. View Addsubview:toolbar];
  16. //do any additional setup after loading the view from its nib.



After running the following interface:

IOS Navigationcontroller Toolbar Learning notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.