1、此方法只是返回按钮上增加一些你想要的操作。
- (void)viewDidLoad {
UIBarButtonItem* leftBarItem=[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
self.navigationItem.backBarButtonItem=leftBarItem;
}
-(void)backaction{
NSLog(@"返回");
}
2、修改返回按钮的样式以及方法。
- (void)viewDidLoad {
UIBarButtonItem* leftBarItem=[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
self.navigationItem.leftBarButtonItem= leftBarItem;
}
-(void)backaction{
NSLog(@"返回");
}
3、自定义按钮覆盖。
- (void)viewDidLoad {
UIButton *leftButton = [UIButton buttonWithType: UIButtonTypeCustom] ;
leftButton.frame=CGRectMake(0,0,30,30);
[leftButton setTitle:@"<" forState:UIControlStateNormal];
[leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[leftButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft] ;
UIBarButtonItem* leftBarItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton] ;
self.navigationItem.leftBarButtonItem= leftBarItem;
self.navigationController.interactivePopGestureRecognizer.enabled=YES;
[leftButton addTarget:self action:@selector(backaction) forControlEvents:UIControlEventTouchUpInside];
}
-(void)backaction{
NSLog(@"返回");
}