Self-sensing system provides Backbutton is still very concise, beautiful. But if you want to customize the Backbutton, you need to pay attention to a lot of details of the problem, the introduction of two ways to customize:
A: Set Backbutton background picture, the advantage of this method is not to destroy the system drawer effect, do not need to implement the Pop method to return to the previous page, but its disadvantage is that if the size of the picture and the size of the BACKBUTTON requirements are inconsistent will stretch the picture, this time it will be difficult to see , the specific code implementation process is as follows:(note that this is implemented in the parent page)
1 //set the style of the return key2UIImage *normalimage = [[UIImage imagenamed:@"Btn_backitem"] Resizableimagewithcapinsets:uiedgeinsetsmake (0, NormalImage.size.width,0,0)];3 4 [[Uibarbuttonitem appearance]setbackbuttonbackgroundimage:normalimage Forstate:uicontrolstatenormal Barmetrics:uibarmetricsdefault];5 6 //Hide Title7 [[Uibarbuttonitem appearance] Setbackbuttontitlepositionadjustment:uioffsetmake (Nsintegermin, NSIntegerMin) Forbarmetrics:uibarmetricsdefault];8 9[Self.navigationcontroller Pushviewcontroller:_controller Animated:yes];
Two: Self-customization Leftbarbutton to achieve the same effect, shortcomings: cumbersome procedures, the system has destroyed the drawer effect, the advantages: You can define the return of any form of the key, the implementation of the Code as follows:
-(void) viewdidload {[Super viewdidload]; Do any additional setup after loading the view. Self.view.backgroundColor = [Uicolor Whitecolor]; Set the picture to button UIImage *iamge = [UIImage imagenamed:@ "Btn_backitem"]; UIButton *backbutton = [UIButton buttonwithtype:uibuttontypecustom]; Backbutton.frame = CGRectMake (0, 0, 30, 30); [Backbutton setbackgroundimage:iamge Forstate:uicontrolstatenormal]; Add an event to the button [Backbutton addtarget:self action: @selector (Skiptoviewcontroller) forControlEvents: UIControlEventTouchUpInside]; Uibarbuttonitem *batbutton = [[Uibarbuttonitem Alloc]initwithcustomview:backbutton]; Self.navigationItem.leftBarButtonItem = Batbutton; Make sure the drawer effect of the system is useful self.navigationController.interactivePopGestureRecognizer.enabled = YES; Self.navigationController.interactivePopGestureRecognizer.delegate = nil;} -(void) skiptoviewcontroller{[Self.navigationcontroller Poptorootviewcontrolleranimated:yes];}
Self-customizing Backbutton