IOS: Toolbars and navigation bars for the navigation bar

Source: Internet
Author: User

////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.//#import<UIKit/UIKit.h>@interfaceTestviewcontroller:uiviewcontroller@end@implementationTestviewcontroller-(void) loadview{NSLog (@"Load View"); //Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview;}@end//--------------View Controller Object--------------@interfacehelloworldviewcontroller:uiviewcontroller{Uitoolbar*ToolBar;}@end@implementationHelloworldviewcontroller-(void) loadview{NSLog (@"Load View"); //Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview; //sets the toolbar and displays[self setnavbarandshow]; [Self setusertoolbarandshow];}//-----------Set the navigation bar and display the------------------(void) setnavbarandshow{Self.navigationItem.leftBarButtonItem= [[Uibarbuttonitem alloc] Initwithtitle:@"Next"Style:uibarbuttonitemstyleplain target:self Action: @selector (Pushview:)]; Self.navigationItem.rightBarButtonItem= [[Uibarbuttonitem alloc] Initwithtitle:@"Prev"Style:uibarbuttonitemstyleplain target:self Action: @selector (Popview:)]; [Self.navigationcontroller Setnavigationbarhidden:no]; //show the previously hidden navigation bar}-(void) Pushview: (ID) sender{NSLog (@"Push View"); [Self.navigationcontroller Pushviewcontroller:[[testviewcontroller Alloc]init] animated:yes];}-(void) Popview: (ID) sender{NSLog (@"Pop View"); [Self.navigationcontroller Popviewcontrolleranimated:yes];}//------------Set the toolbar and display the---------------(void) setnavtoolbarandshow{//sets the toolbar on the Navigationcontroller and displaysUibarbuttonitem *one =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:nil Action:nil]; Uibarbuttonitem*two =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitembookmarks target:nil Action:nil]; Uibarbuttonitem*three =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemaction target:nil Action:nil]; Uibarbuttonitem*four =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemedit target:nil Action:nil]; Uibarbuttonitem*flexitem =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil Action:nil]    ; [Self Settoolbaritems:[nsarray arraywithobjects:flexitem, one, Flexitem, I, Flexitem, three, Flexitem, four, FlexItem,        Nil]]; [Self.navigationcontroller Settoolbarhidden:no animated:no];}-(void) setusertoolbarandshow{//set up a custom Toolbal[Self.navigationcontroller Settoolbarhidden:yes Animated:yes]; Uibarbuttonitem*addbutton =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemsearch target:nil Action:nil]; ToolBar= [[Uitoolbar alloc] Initwithframe:cgrectmake (0.0, Self.view.frame.size.height-toolbar.frame.size.height-44.0, Self.view.frame.size.width,44.0)];    [ToolBar Setbarstyle:uibarstyledefault]; Toolbar.autoresizingmask=Uiviewautoresizingflexibletopmargin;    [ToolBar Setitems:[nsarray Arraywithobject:addbutton]; [Self.view Addsubview:toolbar];}@end//----------------The delegate object--------------------@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window; @property (nonatomic, retain) Uinavigationcontroller*nav;@end@implementationhelloworldappdelegate@synthesizewindow;@synthesizenav;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Helloworldviewcontroller*viewcontroller =[[Helloworldviewcontroller alloc]init]; Self.nav=[[Uinavigationcontroller Alloc]initwithrootviewcontroller:viewcontroller];        [Self.nav Setnavigationbarhidden:yes]; //hide the navigation bar at the top of the view[Self.nav Settoolbarhidden:yes];//hide the toolbar at the bottom of the viewSelf.window.rootViewController=Self.nav; [Self.window makekeyandvisible];}@end//---------------Program Entry---------------------intMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}

IOS: Toolbars and navigation bars for the navigation bar

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.