UINavigationController uses

1, Introduction to UINavigationController

          Navigation controller, commonly used in ios

          Use stack storage. The root view controller is at the bottom of the stack.

 

[self.navigationController pushViewController:viewController animated:YES]; //Push into the viewController view controller
[self.navigationController popViewControllerAnimated:YES]; //Pop the stack and return to the previous view controller
[self.navigationController popToViewController:UIViewController animated:YES]; //Return to the specified attempt controller
[self.navigationController popToRootViewControllerAnimated:YES]; //Return to the root controller    

 

 

2, the structure of UINavigationController

 

          UINavigationController Yu Navigation bar, Navigation View, Navigation too bar, etc.;     

 

3, the creation of UINavigationController

             UINavigationController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor groupTableViewBackgroundColor];  
    ViewController *rootVC = [[ViewController alloc] init];
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController: rootVC];
    [self.window setRootViewController: navigation];
    [self.window makeKeyAndVisible];
    return YES;
}

 

4,UINavigationBar

               (1) Default NavigationBar

                  navigationBar--navigation bar, the default is transparent after iOS7, and it was opaque by default before iOS7.

                  When the navigationBar is transparent, it will overlap a part of the area with the contentView

                  The navigationBar is opaque, and the ContentView follows the navigationBar

                  The default height of navigationBar is 44 in vertical screen and 32 in horizontal screen.

               (2) Customize NavigationBar

[self.navigationController.navigationBar setTranslucent: NO]; //Show NavigationBar
self.navigationController.navigationBar.backgroundColor = [UIColor redColor]; // Set the color of the navigation bar
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tupianName"] forBarMetrics:UIBarMetricsCompact]; //Navigation bar plus background image

               (3) Customize the left button

- (void)viewDidLoad {
    [super viewDidLoad];
    // Customize the left button of the navigation bar
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    leftBtn.frame = CGRectMake(0, 10, 93, 30);
    leftBtn.backgroundColor = [UIColor orangeColor];
    [leftBtn addTarget:self action:@selector(onTap) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView: leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
}

                (4) Customize the right button    

                         Similar to the left button, with the following differences:

self.navigationItem.rightBarButtonItem = rightItem;

                (5) Customize the middle view

UIView * centerView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, 120, 30)];
centerView.backgroundColor = [UIColor greenColor];
self.navigationItem.titleView = centerView;

      

5,UINavigationToolbar

               (1) Display Toolbar

[self.navigationController setToolbarHidden:NO animated:YES] ;

               (2) Add UIBarButtonItem on ToolBar

   UIBarButtonItem *camera=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(ClickToolBarButton)];  
   [camera setWidth:80];  
   UIBarButtonItem *refresh=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(ClickToolBarButton)];  
   [refresh setWidth:80];  
   UIBarButtonItem *reply=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(ClickToolBarButton)];  
   [reply setWidth:80];  
   UIBarButtonItem *compose=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(ClickToolBarButton)];  
   [compose setWidth:80];  
     
   UIBarButtonItem *splitspace=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];  
     
   [self setToolbarItems:[NSArray arrayWithObjects:splitspace,camera,splitspace,refresh,splitspace,reply,splitspace,compose,splitspace, nil nil]];  
    

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326678935&siteId=291194637