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. If you use self. navigationitem. leftbarbuttonitem. title in the current viewcontroller
= @ "Back"; or 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]) {// the return button of the next interface uibarbuttonitem * temporarybarbuttonitem = [[uibarbuttonitem alloc] init]; temporarybarbuttonitem. title = @ "back" using temporarybarbuttonitem.tar get = self; temporarybarbuttonitem. action = @ selector (Back :); self. navigationitem. backbarbuttonitem = temporarybarbuttonitem; [temporarybarbuttonitem release];} return self ;}
. 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;}
Address: http://blog.csdn.net/jinglijun/article/details/7001356