Most of the time we use navigationcontroller because of the previous navigationcontroller. the title string is too long, which makes the return button of the next interface very long and ugly. To make it more beautiful, we can change the title of the return button to back or use a custom image.
1. Change the title of the return button to back: here we need to note that the following code should be written in the previous viewcontroller. In the current viewcontroller, whether you use self. navigationitem. leftbarbuttonitem. title = @ "back"; Use self. navigationitem. backbarbuttonitem. title = @ "back"; the title of the return button is not modified. The Code is as follows:
- -(Void) Back :( ID) sender {
- [Self. navigationcontroller popviewcontrolleranimated: Yes];
- }
- // The designated initializer. Override if you create the Controller programmatically and want to perform customization that is not appropriate for viewdidload.
- -(ID) initwithnibname :( nsstring *) nibnameornil bundle :( nsbundle *) nibbundleornil {
- If (Self = [Super initwithnibname: nibnameornil Bundle: nibbundleornil]) {
- // Return button of the next interface
- Uibarbuttonitem * temporarybarbuttonitem = [[uibarbuttonitem alloc] init];
- Temporarybarbuttonitem. Title = @ "back ";
- Temporarybarbuttonitem.tar get = self;
- Temporarybarbuttonitem. Action = @ selector (Back :);
- Self. navigationitem. backbarbuttonitem = temporarybarbuttonitem;
- [Temporarybarbuttonitem release];
- }
- Return self;
- }
2. Use the custom image modification return button:
- -(Ibaction) backaction {
- [Self. navigationcontroller popviewcontrolleranimated: Yes];
- }
- // The designated initializer. Override if you create the Controller programmatically and want to perform customization that is not appropriate for viewdidload.
- -(ID) initwithnibname :( nsstring *) nibnameornil bundle :( nsbundle *) nibbundleornil {
- If (Self = [Super initwithnibname: nibnameornil Bundle: nibbundleornil]) {
- // Custom Initialization
- Uibutton * backbutton = [uibutton buttonwithtype: uibuttontypecustom];
- Backbutton. Frame = cgrectmake (0.0, 0.0, 40.0, 27.0 );
- [Backbutton setimage: [uiimage imagenamed: @ "btn_back_off.png"] forstate: uicontrolstatenormal];
- [Backbutton setimage: [uiimage imagenamed: @ "btn_back_on.png"] forstate: uicontrolstateselected];
- [Backbutton addtarget: Self action: @ selector (backaction) forcontrolevents: uicontroleventtouchupinside];
- Uibarbuttonitem * temporarybarbuttonitem = [[uibarbuttonitem alloc] initwithcustomview: backbutton];
- Temporarybarbuttonitem. Style = uibarbuttonitemstyleplain;
- Self. navigationitem. leftbarbuttonitem = temporarybarbuttonitem;
- [Temporarybarbuttonitem release];
- }
- Return self;
- }