Navigation Controller
Appdelegate
Viewcontroller * VC = [[Viewcontroller alloc] init];
Uinavigationcontroller * nav = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC];
Self.window.rootViewController = nav;
Specifically set in the Viewcontroller
Set Title
Self.title = @ "Home Hello good-bye haha cup";
Add navigation bar Left button, set System Style button
Uibarbuttonitem * Leftbarbutton = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera Target:nil Action:nil];
Self.navigationItem.leftBarButtonItem = Leftbarbutton;
Set Text button
Uibarbuttonitem * RightBarButton1 = [[Uibarbuttonitem alloc] initwithtitle:@ "More" Style:uibarbuttonitemstyleplain Target:self Action: @selector (RightAction1:)];
Set Picture button
Uibarbuttonitem * RightBarButton2 = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "Setting_item"] style: Uibarbuttonitemstyleplain Target:nil Action:nil];
Self.navigationItem.rightBarButtonItems = @[rightbarbutton1,rightbarbutton2];
Modify Button Color
Self.navigationController.navigationBar.tintColor = [Uicolor Greencolor];
Sets the color of the Navigationbar, which is opaque.
Self.navigationController.navigationBar.barTintColor = [Uicolor Orangecolor];
Set the Navigationbar style, set the Bartintcolor function to fail
Self.navigationController.navigationBar.barStyle = Uibarstyledefault;
Set whether Navigationbar is transparent
Self.navigationController.navigationBar.translucent = NO;
Nsdictionary * dict = @{nsfontattributename:[uifont systemfontofsize:20],
Nsforegroundcolorattributename:[uicolor Whitecolor]};
Set button colors individually
[Self.navigationItem.leftBarButtonItem settitletextattributes:dict Forstate:uicontrolstatenormal];
Nsdictionary * titledict = @{nsfontattributename:[uifont systemfontofsize:30],
Nsforegroundcolorattributename:[uicolor Yellowcolor]};
Set the title of the navigation bar
[Self.navigationController.navigationBar settitletextattributes:titledict];
Setting hints
Self.navigationItem.prompt = @ "I am the hint";
Hide Navigation
Self.navigationController.navigationBarHidden = YES;
Modify the Back button
Uibarbuttonitem * item = [[Uibarbuttonitem alloc] init];
Item.title = @ "return";
Self.navigationItem.backBarButtonItem = Item;
UIButton * btn = [UIButton Buttonwithtype:uibuttontypesystem];
[btn settitle:@ "Next page" Forstate:uicontrolstatenormal];
[Btn addtarget:self Action: @selector (nextaction:) forcontrolevents:uicontroleventtouchupinside];
Btn.frame = CGRectMake (100, 100, 100, 100);
[Self.view ADDSUBVIEW:BTN];
}
-(void) Nextaction: (UIButton *) btn {
Nextviewcontroller * NEXTVC = [[Nextviewcontroller alloc] init];
[Self.navigationcontroller PUSHVIEWCONTROLLER:NEXTVC animated:yes];//Next Page method
}
Custom navigation Bar
The background of the navigation controller must be set, otherwise there is a lag phenomenon
Custom navigation Titleview
Uisegmentedcontrol * segment = [[Uisegmentedcontrol alloc] initwithitems:@[@ "message" @ "phone"];
Segment.frame = CGRectMake (0, 0, 60, 30);
Self.navigationItem.titleView = segment;
Set the Back button, but the effect is poor-the color is not very good
Uibarbuttonitem * Backitem = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "BACKBTN"] Style:UIBarButto Nitemstyleplain Target:nil Action:nil];
Self.navigationItem.backBarButtonItem = Backitem;
Jump to Next page
-(void) Upaction {
How to navigate the controller
Secondviewcontroller * SECONDVC = [[Secondviewcontroller alloc] init];
[Self.navigationcontroller PUSHVIEWCONTROLLER:SECONDVC Animated:yes];
Viewcontroller * VC = [[Viewcontroller alloc] init];
Uinavigationcontroller * nav = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC];
[Self Presentviewcontroller:nav animated:yes completion:nil];
}
UIButton * btn = [UIButton Buttonwithtype:uibuttontypecustom]
// ;
[Btn setimage:[uiimage imagenamed:@ "backbtn"] forstate:uicontrolstatenormal];
Btn.frame = CGRectMake (0, 0, 30, 30);
[Btn addtarget:self Action: @selector (returnaction:) forcontrolevents:uicontroleventtouchupinside];
//
Custom return button, return gesture disappears
Uibarbuttonitem * item = [[Uibarbuttonitem alloc] initwithcustomview:btn];
//
Self.navigationItem.leftBarButtonItem = Item;
BaseNavViewController.h
Appearance called once, acting on the entire app
Uinavigationbar * bar = [Uinavigationbar appearance];
Uibarbuttonitem * Baritem = [Uibarbuttonitem appearance];
Set the color of the Uinavigationbar
Bar.bartintcolor = [Uicolor Yellowcolor];
Nsdictionary * titledict = @{nsfontattributename:[uifont systemfontofsize:20],nsforegroundcolorattributename:[ Uicolor Greencolor]
};
Set the title of Uinavigationbar
[Bar settitletextattributes:titledict];
Set the background image for Uinavigationbar
[Bar setbackgroundimage:[uiimage imagenamed:@ "NAV"] forbarmetrics:uibarmetricsdefault];
Nsdictionary * titleitemdict = @{nsfontattributename:[uifont systemfontofsize:15],nsforegroundcolorattributename:[ Uicolor Magentacolor]
};
[Baritem settitletextattributes:titleitemdict Forstate:uicontrolstatenormal];
Since the left item has been customized, the gesture disappears, so add this sentence and restore the gesture.
Self.interactivePopGestureRecognizer.delegate = self;
}
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) Animated {
Self.viewcontrollers get all the managed controllers, self.viewControllers.count the number of stacks
if (Self.viewControllers.count) {
UIButton * btn = [UIButton Buttonwithtype:uibuttontypecustom]
;
[Btn setimage:[uiimage imagenamed:@ "backbtn"] forstate:uicontrolstatenormal];
Btn.frame = CGRectMake (0, 0, 30, 30);
[Btn addtarget:self Action: @selector (returnaction:) forcontrolevents:uicontroleventtouchupinside];
Custom return button, return gesture disappears
Uibarbuttonitem * item = [[Uibarbuttonitem alloc] initwithcustomview:btn];
ViewController.navigationItem.leftBarButtonItem = Item;
}
[Super Pushviewcontroller:viewcontroller animated:animated];
}
Navigation controllers and custom navigation controllers