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