Unify the "Back" button style for all pages of the app
If you want to uniformly set the return button style for all the app's pages, first customize the Wznavigationcontroller class to inherit the Uinavigationcontroller class, and then override Pushviewcontroller in the custom class: Animated: The method can be.
// override Navc's Pushvc method so that the "back" button -(void) Pushviewcontroller: (Uiviewcontroller *) is set to the left of push-in VC. Viewcontroller animated: (BOOL) Animated { = [[Uibarbuttonitem alloc]initwithtitle:@ ' return " style:uibarbuttonitemstyleplain Target:nil Action:nil]; // this will immediately invoke the Viewdidload method of the push VC, which must be placed on the last side, otherwise the above code will overwrite the code in Viewdidload, causing the viewdidload setting to be invalid. [Super Pushviewcontroller:viewcontroller animated:animated]; Animated for No, all VC no animation }
Unify the Leftbarbutton button style for all app pages demo
//WZNavigationController.h#import<UIKit/UIKit.h>@interfaceWznavigationcontroller:uinavigationcontroller@end//WZNAVIGATIONCONTROLLER.M#import "WZNavigationController.h"@implementationWznavigationcontroller//This method is called the first time the class is used (only once)+ (void) Initialize {//Uinavigationbar *bar = [Uinavigationbar appearance]; this background color will be used by NAV for all other custom classes after thisUinavigationbar *bar = [Uinavigationbar appearancewhencontainedin:[selfclass], nil];//valid only in this class and subclass[Bar Setbackgroundimage:[uiimage imagenamed:@"Navigationbarbackgroundwhite"] forbarmetrics:uibarmetricsdefault];}- (void) viewdidload {[Super viewdidload]; //sets the background picture of the navigation bar (which is called each time the Nav is created)//[Self.navigationbar setbackgroundimage:[uiimage imagenamed:@ "Navigationbarbackgroundwhite"] forBarMetrics: Uibarmetricsdefault]; //set the navigation bar staining stroke color//Self.navigationBar.tintColor = [Uicolor blackcolor];}/** * Practice 1. Apple will only let you in the current VC modify the next VC left back button name, can not modify the font color and highlight color, also cannot add custom button; * via Self.navigationBar.tintColor = [Uicolor Blackcolor]; You can modify the return color (the default blue), but the method does not implement long press "back" when highlighting the red. *//*//Override the PUSHVC method of NAVC to set the left "back" button-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller for push incoming VC Animated: (BOOL) Animated {viewController.navigationItem.backBarButtonItem = [[Uibarbuttonitem alloc]initwithtitle:@ "Return" Style:uibarbuttonitemstyleplain Target:nil Action:nil]; This will immediately invoke the Viewdidload method of the push VC, which must be placed on the last side, otherwise the above code will overwrite the code in Viewdidload, causing the viewdidload setting to be invalid. [Super Pushviewcontroller:viewcontroller animated:animated];//animated for No, all VC no animation}*//** * Practice 2. Because Apple does not allow the addition of custom buttons to the Back button on the next page managed by this page, we can customize the Leftbarbuttonitem of the next page;*///override Navc's Pushvc method to set the "Back" button on the left side of push-in VC- (void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) Animated {if(Self.viewControllers.count >=1) {UIButton*BTN =[UIButton Buttonwithtype:uibuttontypecustom]; Btn.bounds= CGRectMake (0,0, -, +);//size must be set[BTN Settitle:@"return"Forstate:uicontrolstatenormal]; [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; [btn Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatehighlighted]; [Btn setimage:[uiimage imagenamed:@"Navigationbuttonreturn"] Forstate:uicontrolstatenormal]; [Btn setimage:[uiimage imagenamed:@"Navigationbuttonreturnclick"] forstate:uicontrolstatehighlighted];//There is no need to stretch, so setimage, can not be written in the wrong backgroundimage//set the BTN content horizontally on the leftBtn.contenthorizontalalignment =Uicontrolcontenthorizontalalignmentleft; //set the padding on the 10 to make it more left (-10 special usage)Btn.contentedgeinsets = Uiedgeinsetsmake (0, -Ten,0,0); //btn Adding events[btn addtarget:self Action: @selector (back) forcontrolevents:uicontroleventtouchupinside]; ViewController.navigationItem.leftBarButtonItem=[[Uibarbuttonitem alloc]initwithcustomview:btn]; //Hide Bottom Bar when VC is push into Navviewcontroller.hidesbottombarwhenpushed =YES; } //this will immediately invoke the Viewdidload method of the push VC, which must be placed on the last side, otherwise the above code will overwrite the code in Viewdidload, causing the viewdidload setting to be invalid. [Super Pushviewcontroller:viewcontroller animated:animated];//animated for No, all VCs no animations}- (void) Back {[Self popviewcontrolleranimated:yes];}@end
[BS-10] Unified Settings "Back" button style for all pages of the app