IOS Navigation Custom Settings item

Source: Internet
Author: User

1. Custom Navigationcontroller:

@interface Customnavigationcontroller:uinavigationcontroller

2. override the Push method to intercept the push-in controller :

- (void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated{//determine if the controller that the push comes in is the root controller     if(Self.childViewControllers.count >0)     {          //Hide Tabbarbottom when push (application hierarchy Tabbarcontroller-Navigationcontroller)viewcontroller.hidesbottombarwhenpushed =YES; //add left item to NavigationitemViewController.navigationItem.leftBarButtonItem = [Uibarbuttonitem itemwithtarget:self image:@ "Leftbarbuttonimage"highlightedimage:@"leftbarbuttonimage_highlighted"Action: @selector (Clickleftitem)];           //add left item to NavigationitemViewController.navigationItem.rightBarButtonItem = [Uibarbuttonitem itemwithtarget:self image:@] Rightbarbuttonimage"highlightedimage:@ "rightbarbuttonimage_highlighted"Action: @selector (Clickrightitem)];  } [Super Pushviewcontroller:viewcontroller Animated:yes]; }

Item Click event:

-(void) clickleftitem{     //  Method     [self Popviewcontrolleranimated:yes];}
-(void) clickleftitem{     // Method}    

3. By Category, customize the Barbuttonitem creation method:

/** *  Create Item * *  @param imageName            Item picture *  @param highlightedimagename Item's highlighted picture *  @param Target               Item Click event Performer *  @param action               Item Click event * */+ (Uibarbuttonitem *) Itemwithtarget: (ID) Target Image: ( NSString *) ImageName highlightedimage: (NSString *) highlightedimagename action: (SEL) action{    //Create button    UIButton *button = [UIButton buttonwithtype:uibuttontypecustom];    Set button picture    [button setimage:[uiimage Imagenamed:imagename] forstate:uicontrolstatenormal];    [Button Setimage:[uiimage Imagenamed:highlightedimagename] forstate:uicontrolstatehighlighted];    Set Button size    button.size = button.currentImage.size;//Avoid picture stretching    //Setting button listening events    [button Addtarget:target action : Action Forcontrolevents:uicontroleventtouchupinside];       return item return    [[Uibarbuttonitem alloc] Initwithcustomview:button];}

IOS Navigation Custom Settings item

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.