ios 5将导航控制器中后退button的背景更改为透明

我已经定制了导航控制器标题栏的背景图像,但我真的很努力将后退button的背景颜色更改为透明,以便它与下面的绿色标题栏相匹配。 我对iOS开发相当新颖。 任何人都可以build议可以做什么?

以下是我用来更改导航控制器标题栏的代码,以防万一:

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) { UIImage *image = [UIImage imageNamed:@"greenbar.png"]; [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; // [[UIBarButtonItem appearance] setBackButtonBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; } //change back button image } 

编辑 :经过一些研究,我设法得到我想要的。 这是更改后退button的背景图片的代码:

  UIImage *image1 = [UIImage imageNamed:@"back-bt.png"]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

上面的代码将图像添加到导航控制器中的所有后退button。

您不能更改默认后退button的外观,但您可以创build自己的button来replace它。

 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) { UIImage *image = [UIImage imageNamed:@"greenbar.png"]; [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; // [[UIBarButtonItem appearance] setBackButtonBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; } //change back button image if(self.navigationController.viewControllers.count > 1) { UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; [backButton setTitle:@"Back" forState:UIControlStateNormal]; [backButton addTarget:self action:@selector(didTapBackButton:) forControlEvents:UIControlEventTouchUpInside]; backButton.frame = CGRectMake(0.0f, 0.0f, 64.0f, 41.0f); UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton]; self.navigationItem.leftBarButtonItem = backButtonItem; } } - (void) didTapBackButton:(id)sender { if(self.navigationController.viewControllers.count > 1) { [self.navigationController popViewControllerAnimated:YES]; } }