我已经在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;
但是我收到了这个错误,似乎有两个后退按钮重叠,用默认的按钮定制。我试图隐藏左栏按钮项,然后都隐藏。
非常感谢
答案 0 :(得分: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;
goback方法: -
- (void)goback
{
[self.navigationController popViewControllerAnimated:YES];
}