user1120133
user1120133

Reputation: 3234

change the color of navigation bar of UINavigationController

I m trying to change the color of navigation bar of UINavigationController by using

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

in the below given code but its not working.

 #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;
}

Can anyone tell why it is not changing the color of the navigation bar of the UINavigation Controller.

Thanks in advance.

Upvotes: 0

Views: 2842

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89559

Looking at these two lines:

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

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

What connects the first navigationController with self.navigationController?

Nothing, as far as I can tell.

You need to assign self.navigationController to navigationController.

Something like:

self.navigationController = navigationController;

Upvotes: 4

Related Questions