更改UINavigationController导航栏的颜色

时间:2012-01-08 19:46:11

标签: iphone

我试图使用

更改UINavigationController导航栏的颜色
self.navigationController.navigationBar.tintColor = [UIColor brownColor];   

在下面给出的代码中,但它不起作用。

 #import "uitextviewAppDelegate.h"

#import "uitextviewViewController.h"

@implementation uitextviewAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize navigationController = _navigationController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Override point for customization after application launch.
self.viewController = [[uitextviewViewController alloc] init];

UINavigationController *navigationController=[[UINavigationController alloc] init];

self.navigationController.navigationBar.tintColor = [UIColor brownColor];  

[navigationController pushViewController:_viewController animated:YES];

[_window addSubview:navigationController.view];

self.window.rootViewController = self.viewController;

[self.window makeKeyAndVisible];

return YES;
}

任何人都可以说明为什么它没有改变UINavigation控制器导航栏的颜色。

提前致谢。

1 个答案:

答案 0 :(得分:4)

看看这两行:

UINavigationController *navigationController=[[UINavigationController alloc] init];

self.navigationController.navigationBar.tintColor = [UIColor brownColor];  

第一个navigationControllerself.navigationController之间的连接是什么?

据我所知,没什么。

您需要将self.navigationController分配给navigationController

类似的东西:

self.navigationController = navigationController;