The iOS navigation bar uses

Source: Internet
Author: User

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

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.