我有一个以编程方式创建的UINavigationController:
MessageTableViewController* homeStream = [[MessageTableViewController alloc] initWithNibName:@"MessageTableViewController" bundle:nil];
homeStream.fetchHomeStream = YES;
homeStream.title = @"Home";
UINavigationController* navBarController = [[UINavigationController alloc] initWithRootViewController:homeStream];
navBarController.tabBarItem.image = [UIImage imageNamed:@"hometab.png"];
[homeStream release];
我有一个名为STNavigationBar的自定义UINavigationBar。如何使用STNavigationBar而不是UINavigationController中的默认UINavigationBar?
答案 0 :(得分:3)
我最终使用的是iOS5 UIKit外观代理:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"header"] forBarMetrics:UIBarMetricsDefault];
不需要子类或类别。
答案 1 :(得分:0)
编辑,以下答案在iOS 5上不再有效。
您不能将其设置为现有实例,因为 UINavigationController 具有 navigationBar 的 readonly 属性。我不认为继承UINavigationController是你想要的。
我认为最好的方法是创建一个扩展UINavigationBar的类别,如讨论here。