IOS 9th Lesson Navigation view Navigationview

Source: Internet
Author: User
Tags reserved

Navigation view is similar to Viewpager in Android

The navigation bar is related to Navigationitem, the controller is related to Navigationcontroller




0: First, or through the pure code to achieve

0: Delete 3 files Viewcontroller.h,viewcontroller.m,main.storyboard

1: Modify click on the blue button on the left, then select general-"Developer info-" main interface, will this main interface clear sky

1: Modify the Appdeleget

APPDELEGATE.M//Ninenavigationdemo/////Created by thousand Ya Dad on 16/10/15. COPYRIGHT©2016 year Kodulf.
All rights reserved.


#import "AppDelegate.h" #import "FirstViewController.h" @interface appdelegate () @end @implementation appdelegate -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//Ov
    Erride point for customization after application launch.
    Self.window = [[UIWindow alloc]initwithframe:[uiscreen mainscreen].bounds];
    
       [Self.window makekeyandvisible];
    Firstviewcontroller *firstviewcontroller = [[Firstviewcontroller alloc]init]; Uinavigationcontroller *navigationcontroller = [[Uinavigationcontroller alloc]initwithrootviewcontroller:
    Firstviewcontroller];
    
    [Self.window Setrootviewcontroller:navigationcontroller];
return YES; }-(void) Applicationwillresignactive: (uiapplication *) application {//Sent when the application was about to move FR Om Active to Inactive STATe. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or the US
    Er quits the application and it begins the transition to the background state. Use the To pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
Games should to pause the game. }-(void) Applicationdidenterbackground: (uiapplication *) Application { , save user data, invalidate timers, and store enough application state information to restore your application to its cur
    Rent state in case it is terminated later. If your application supports background execution, this is called instead of Applicationwillterminate:when the
User quits. }-(void) Applicationwillenterforeground: (uiapplication *) application {//called as part of the transition from the Background to the inactive state; Here you can undo many of the changes made on entering the BACKground.  }-(void) Applicationdidbecomeactive: (uiapplication *) application {//Restart any tasks this were paused (or not yet started) while the application is inactive.
If the application is previously in the background, optionally refresh the user interface. }-(void) Applicationwillterminate: (uiapplication *) application {//called when the application was about to Terminat E. Save data if appropriate.
Also applicationdidenterbackground:.
 } @end



2: Create three controllers,

2.1: First Controller:

FIRSTVIEWCONTROLLER.M//Ninenavigationdemo/////Created by thousand Ya Dad on 16/10/15. COPYRIGHT©2016 year Kodulf.
All rights reserved. #import "FirstViewController.h" #import "SecondViewController.h" @interface Firstviewcontroller () @end @implementa tion Firstviewcontroller-(void) Viewdidload {//navigation bar coordinates (0,20, width, 44);//navigation bar related to Navigationitem, controller related is Navigat
    Ioncontroller [Super Viewdidload];
    [Self settitle:@ "first page"]; [Self.view setbackgroundcolor:[uicolor greencolor]];//uibarbuttonitem *item =[[uibarbuttonitem alloc]
    Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self Action:null];
    
    Set the navigation item Self.navigationItem.rightBarButtonItem = Item;
    Customize view as the navigation menu UIButton *itembutton = [UIButton buttonwithtype:uibuttontypecustom];
    [Itembutton settitle:@ "UIButton" forstate:uicontrolstatenormal];
    [Itembutton Settitlecolor:[uicolor Greencolor] forstate:uicontrolstatehighlighted]; [Itembutton setframe:cgrectmake (0, 0,100,100)];
    
    Uibarbuttonitem *item2 = [[Uibarbuttonitem Alloc]initwithcustomview:itembutton];
    
    Set multiple button Self.navigationItem.leftBarButtonItems = @[item,item2];
    Set navigation blue above the color self.navigationController.navigationBar.backgroundColor = [Uicolor Bluecolor]; [Self.navigationController.navigationBar setbackgroundimage:[uiimage imagenamed:@ "Background"] Forbarmetrics:
    Behind the uibarmetricscompact];//is the rendering style of the picture.
    Uibarmetricsdefault default, background pictures and colors are not repeatable, like here the picture will cover the color of the//UIBARMETRICSCOMPAC will use the color of the picture//note, here's the size inside the position,
    UIButton *button = [UIButton buttonwithtype:uibuttontypecustom];
    [Button settitle:@ "Push" forstate:uicontrolstatenormal];
    [Button Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatehighlighted];
    [Button Setbackgroundcolor:[uicolor Blackcolor]];
    [Button Setframe:cgrectmake (100,80,100,100)]; [Button addtarget:self action: @selector (Pushcontroller) forcontrolevents:uicontroleventtouchupinside];//
triggered when clicked internally
    [Self.view Addsubview:button];
Navigation bar controller in the control of multiple views of the time the jump//Do any additional setup after loading the view.
    //equivalent to combat operations-(void) pushcontroller{NSLog (@ "clicked on");
[Self.navigationcontroller Pushviewcontroller:[[secondviewcontroller Alloc]init] Animated:YES];
    }-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
 } * * @end

2.2 Second Controller

SECONDVIEWCONTROLLER.M//Ninenavigationdemo/////Created by thousand Ya Dad on 16/10/15. COPYRIGHT©2016 year Kodulf.
All rights reserved. #import "SecondViewController.h" #import "FirstViewController.h" #import "ThirdViewController.h" @interface Secondviewcontroller () @end @implementation Secondviewcontroller-(void) Viewdidload {//navigation bar is related to Navigationitem, controller
    The related is Navigationcontroller [super viewdidload];
    The default switch is to have some cotton.
    [Self.view Setbackgroundcolor:[uicolor Yellowcolor]];
    [Self settitle:@ "second page"]; Multiple child controller objects are common to a navigation bar//Add a unified return button, Simple is a son uibarbuttonitem *leftitem =[[uibarbuttonitem alloc] initwithtitle:@ "
    Fallback "Style:uibarbuttonitemstyleplain target:self action: @selector (Popcontroller)];
    
    
    Self.navigationItem.leftBarButtonItem = Leftitem; Uibarbuttonitem *rightitem =[[uibarbuttonitem alloc]initwithtitle:@ "Next" Style:uibarbuttonitemstyleplain Target:
    
    Self action: @selector (Pushcontroller)]; Do any additional setUp after loading the view.
    Self.navigationItem.rightBarButtonItem = Rightitem; Common set of navigation bars [Self.navigationController.navigationBar settitletextattributes:@{nsforegroundcolorattributename:[
Uicolor Whitecolor]};

}-(void) popcontroller{[Self.navigationcontroller Popviewcontrolleranimated:yes];} -(void) pushcontroller{[Self.navigationcontroller Pushviewcontroller:[[thirdviewcontroller Alloc]init] Animated:
YES];
    }-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
 } * * @end

2.3: The third controller

THIRDVIEWCONTROLLER.M//Ninenavigationdemo/////Created by thousand Ya Dad on 16/10/15. COPYRIGHT©2016 year Kodulf.
All rights reserved. #import "ThirdViewController.h" @interface Thirdviewcontroller () @end @implementation Thirdviewcontroller-(void
    Viewdidload {//navigation bar is related to Navigationitem, the controller is related to Navigationcontroller [Super Viewdidload];
    Do no additional setup after loading the view.
    Pop jump, you can jump to the previous, you can jump to the root, but also jump to the specified [self settitle:@ the third];
    
    [Self.view Setbackgroundcolor:[uicolor Whitecolor]]; Uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc] initwithtitle:@ "return to upper or upper layer" Style:uibarbuttonitemstyleplain
    Target:self Action: @selector (Popviewcontroller)];
    
Navigation bar is related to Navigationitem, the controller is related to the navigationcontroller self.navigationItem.leftBarButtonItem = Leftitem;
    }-(void) popviewcontroller{//You can jump to the first page, or you can jump to the previous page//[self.navigationcontroller Popviewcontrolleranimated:yes]; [Self.navigationcontroller PoptorootviewconTrolleranimated:yes];
    }-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
 } * * @end






Related Article

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.