0

我已经在 appDelegate 中实现了这段代码,以便定制导航栏后退按钮背景图像:

float version = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (version >= 5.0)
    {
        // iPhone 5.0 code here
        UIImage *buttonImage = [[UIImage imageNamed:@"btn_backesp.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 10, 1, 10)];
        [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

    }

    return YES;

但是我得到了这个错误,似乎两个后退按钮重叠,自定义与默认一个。我试图隐藏左栏按钮项目,然后都隐藏。

在此处输入图像描述

非常感谢

4

1 回答 1

4

使用下面的代码设置返回按钮图像,效果很好

UIButton *backBtn     = [UIButton buttonWithType:UIButtonTypeCustom];  
UIImage *backBtnImage = [UIImage imageNamed:@"btn_backesp.png"]  ;  
[backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];  
[backBtn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];  
backBtn.frame = CGRectMake(0, 0, 54, 30);  
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;  
self.navigationItem.leftBarButtonItem = cancelButton;

回退方法:-

- (void)goback
{
    [self.navigationController popViewControllerAnimated:YES];
}
于 2012-05-10T16:56:33.663 回答