Learn about IOS custom navigation controller Uinavigationcontroller_ios

Source: Internet
Author: User

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.

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.