首先自訂UINavigationBar的左側返回按鈕
[cpp] UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,71.5, 44)];
// UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,200, 44)];
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui.png"] forState:UIControlStateNormal] ;
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui_over.png"] forState:UIControlStateHighlighted] ;
// backBtn.backgroundColor = [UIColor redColor];
[backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside] ;
[backBtn setShowsTouchWhenHighlighted:YES] ;
UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = backbutton;
[backBtn release] ;
UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,71.5, 44)];
// UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,200, 44)];
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui.png"] forState:UIControlStateNormal] ;
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui_over.png"] forState:UIControlStateHighlighted] ;
// backBtn.backgroundColor = [UIColor redColor];
[backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside] ;
[backBtn setShowsTouchWhenHighlighted:YES] ;
UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = backbutton;
[backBtn release] ;
編寫點擊返回按鈕所觸發的函數
[cpp] - (void)backButtonClick:(id)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
摘自 zcl369369的專欄