Custom navigation Controller: Bring the common parts of the navigation controller to the unified setting
1, the general navigation bar title font settitletextattribute and background color setbackgroundimage are unified, you can use the Load method Appearancewhencontainedin Unified Settings
2, general navigation bar return button needs customization, generally in addition to the bottom of the stack controller has a navigation bar, other controllers need to hide the bottom of the bar, you can rewrite the pushviewcontroller:animated: method, in this method to implement the function
3, navigation controller right sliding return effect (touch the screen any point, slide right back)
Uiviewcontroller
--navigationitem
Leftbarbuttonitem | Leftbarbuttonitems
NSString Title | UIView Titleview
Rightbarbuttonitem | Rightbarbuttonitems
Backbarbuttonitem
#import "BWNavigationController.h" #import "uibarbuttonitem+item.h" @interface Basenavigationcontroller () <
Uigesturerecognizerdelegate> @end @implementation Bwnavigationcontroller + (void) load {[Super load];
Uinavigationbar *navigationbar = [Uinavigationbar appearancewhencontainedin:self, Nil];
Nsmutabledictionary *dict = [Nsmutabledictionary dictionary];
Dict[nsfontattributename] = [Uifont boldsystemfontofsize:20];
[Navigationbar settitletextattributes:dict]; [Navigationbar setbackgroundimage:[uiimage imagenamed:@ "Navigationbarbackgroundwhite"] forBarMetrics:
Uibarmetricsdefault];
}-(void) viewdidload {[Super viewdidload]; The edge of the screen slides (only on the edge of the screen to trigger the gesture, and cannot trigger the gesture at any point on the screen) Uiscreenedgepangesturerecognizer *edgepangesturerecognizer = (
Uiscreenedgepangesturerecognizer *) Self.interactivepopgesturerecognizer; Sliding gestures (Disable the system's own screen edge sliding gestures, using a custom sliding gesture to achieve a touch on the screen at any point to slide to the right can achieve the return effect) uipangesturerecognizer *pangesturerecognizer = [ Uipangesturerecognizer Alloc] InitwiThTarget:edgePanGestureRecognizer.delegate Action: @selector (handlenavigationtransition:)];
Pangesturerecognizer.delegate = self;
[Self.view Addgesturerecognizer:pangesturerecognizer];
Disable the screen edge of the system sliding gesture edgepangesturerecognizer.enabled = NO; }//Whether trigger gestures are allowed, if the root view controller is not required-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (
Uitouch *) Touch {return self.childViewControllers.count > 1;} -(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated {//Unified settings Return button Nsinteger count =
Self.childViewControllers.count;
if (Count > 0) {viewcontroller.hidesbottombarwhenpushed = YES; ViewController.navigationItem.leftBarButtonItem = [Uibarbuttonitem backbarbuttonitemwithimage:[uiimage imagenamed: @ "Navigationbuttonreturn"] highlightimage:[uiimage imagenamed:@ "Navigationbuttonreturnclick"] tagert:self action:@
Selector (back) title:@ "return"];
} [Super Pushviewcontroller:viewcontroller animated:animated]; }-(VOID) Back {[Self popviewcontrolleranimated:yes];} @end
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.