IOS changes the title of the return button in the navigation bar

Source: Internet
Author: User

In the afternoon, I found a new method. This method is good, and no exception is found.

Uinavigationcontroller must be used in newly written apps to navigate each page. However, because the title of the first-level page is long, the title of the return button leftbuttonitem becomes very long after you enter the second-level page, navigationbar occupies a lot of space and is not beautiful. Therefore, you can use the code to modify the title text of leftbuttonitem, whether it is set to self. navigationitem. leftbarbuttonitem. title = @ "return"; or self. navigationitem. backbarbuttonitem. title
= @ "Return"; the title text will never change. The following solution is relatively simple after you perform a random search on the Internet. The special record is as follows:

Add the following code to the viewdidload method on the first page:

Uibarbuttonitem * identifier = [[uibarbuttonitem alloc] init]; temporarybarbuttonitem. Title = @ "back"; self. navigationitem. backbarbuttonitem = temporarybarbuttonitem; [temporarybarbuttonitem release]

That is, you can use a new button to replace the original return button before navigation.

You can set it as follows, but the disadvantage is that the button will become square and you can add images for modification.

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"                                                                   style:UIBarButtonItemStyleBordered                                                                  target:self                                                                  action:@selector(backToPrevious)];        self.navigationItem.leftBarButtonItem = backButton;    [backButton release];- (void)backToPrevious{    [self.navigationController popViewControllerAnimated:YES];}

The code for adding an image is as follows:

Uibutton * leftbutton = [[uibuttonalloc] initwithframe: cgrectmake (0, 0, 60, 40)]; [leftbutton settitle: @ "return" forstate: uicontrolstatenormal]; [leftbutton setimage: [uiimageimagenamed: @ "success"] forstate: uicontrolstatenormal]; [leftbutton setimage: [uiimageimagenamed: @ "success"] forstate: uicontrolstatehighlighted]; [leftbutton addtarget: selfaction: @ selector (leftaction :) forcontrolevents: uicontroleventtouchupinside]; uibarbuttonitem * leftitem = [[uibarbuttonitemalloc] initwithcustomview: leftbutton]; [leftbutton release. navigationitem. leftbarbuttonitem = leftitem; [leftitem release];

Original post address: http://hi.baidu.com/givingmore/item/134c50e3ef6fcea52e140b71

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.