xcode:6.3.2
ios8.3
Introduction: In Peacetime project development, the use of Uinavigationcontroller is very extensive, many excellent apps are using the navigation bar, navigation bar for view control is very convenient.
Let's take a look at the official picture.
1, new Project Nav
2, add Firstviewcontroller for the root view, add Secondviewcontroller for the view that the root view jumps to
3, in the APPDELEGATE.M file, modify the proxy so that Firstviewcontroller is the root view, as follows:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions { *first = [[Firstviewcontroller alloc] init]; *nav = [[Uinavigationcontroller alloc] initwithrootviewcontroller:first]; [Self.window Setrootviewcontroller:nav]; [Self.window makekeyandvisible]; return YES;}
4, set the relevant properties of Navigationcontroller in Firstviewcontroller.m, as follows:
- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Redcolor]; Self.title=@"Home Page";//Set Title[Self.navigationController.navigationBar setbartintcolor:[uicolor purplecolor];//set the color of the Navigationbar[Self.navigationController.navigationBar Settranslucent:yes];//set the translucency of the NavigationbarSelf.navigationItem.leftBarButtonItem= [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera target:self action: @selector ( Camerastart)];//Set Navigationbar left buttonSelf.navigationItem.rightBarButtonItem= [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self action: @selector ( Tosecond)];//Set Navigationbar right button }
Style:
5, implement Tosecond method push to Secondviewcontroller
-(void) tosecond { *second = [[Secondviewcontroller alloc] init]; [Self.navigationcontroller Pushviewcontroller:second animated:yes];}
6, add the button in secondviewcontroller.m, for pop back to Firstviewcontroller, the code is as follows
- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Bluecolor]; UIButton*button = [[UIButton alloc] Initwithframe:cgrectmake ( -, -, $, +)]; [Button Settitle:@"return"Forstate:uicontrolstatenormal]; Button.backgroundcolor=[Uicolor Blackcolor]; [Button addtarget:self action: @selector (Backtofirstviewcontroller) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; //[Self.navigationController.navigationBar Sethidden:yes];}- (void) Backtofirstviewcontroller {[Self.navigationcontroller popviewcontrolleranimated:yes]; //[Self.navigationController.navigationBar Sethidden:no];}
The styles are as follows:
7, Hide Navigationbar, open comments, set Navigationbar hide, and let Navigationbar show back in the method that returns Firstviewcontroller
[Self.navigationController.navigationBar Sethidden:yes];
Source Address: Https://github.com/rokistar/UsingUINavigationController
The iOS navigation bar uses