就像这段代码一样简单:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Inizializzazione barra di navigazione
[[self navigationController] setNavigationBarHidden:NO];
UINavigationItem* a = [self navigationItem];
[a setTitle:@"SOME TITLE"];
UIImage *background = [UIImage imageNamed:@"header.png"];
CGSize newSize;
newSize.height=100;
[self.navigationController.navigationBar setBackgroundImage:background
forBarMetrics:UIBarMetricsDefault];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
initWithTitle:@"Homefgh"
style:UIBarButtonItemStyleBordered
target:self action:@selector(home)];
self.navigationController.navigationItem.rightBarButtonItem = rightButton;
}
但未显示按钮(在右侧)。我还尝试将代码放在 viewDidLoad 中。viewWillAppear 位于主 UINavigationController 顶部的 UIView 内。奇怪的是背景图像正确显示。