How to set a custom navigation controller global return button---iOS

Source: Internet
Author: User

How can you customize the return keys in the navigation controller all at once.

Ideas:

We can set this custom button on push, and push has a method

-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated{}

In this method Viewcontroller is the object of the push

But to determine if this Viewcontroller is a root controller,

-(void) Pushviewcontroller: (uiviewcontroller *) Viewcontroller animated: (BOOL) animated{

If(Self. childviewcontrollers. Count > 0) { // non-root controller

//The non-root controller needs to set the return button
//Set Back button
UIButton*backbutton = [UIButtonButtonwithtype:Uibuttontypecustom];
[BackbuttonSettitle:@"Return"Forstate:UIControlStateNormal];
[BackbuttonSetImage:[UIImageImagenamed:@ "Navigationbuttonreturn"]Forstate:UIControlStateNormal];
[BackbuttonSetImage:[UIImageImagenamed:@ "Navigationbuttonreturnclick"]Forstate:uicontrolstatehighlighted];
[BackbuttonSettitlecolor:[UicolorBlackcolor]Forstate:UIControlStateNormal];
[BackbuttonSettitlecolor:[UicolorRedcolor]Forstate:uicontrolstatehighlighted];
[BackbuttonAddTarget:SelfAction:@selector(back)forControlEvents:UIControlEventTouchUpInside];

[BackbuttonSizeToFit];

//Attention:Be sure to have the button content in a size,The setting is only effective
Backbutton.Contentedgeinsets=Uiedgeinsetsmake(0, -25,0,0);

//Set Back button
Viewcontroller.Navigationitem.Leftbarbuttonitem= [[UibarbuttonitemAlloc]Initwithcustomview: Backbutton];

}

This is the way to actually perform a jump
[Super Pushviewcontroller: Viewcontroller animated: animated];

}

How to set a custom navigation controller global return button---iOS

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.