Search code examples
iphonethree20

Navigation Bar Style change in *AppDelegate.m


Im using three20 framework and trying to change the top naivagation bar from the standard to UIStatusBarStyleBlackOpaque.

I tried using many things in many places but it does not seem to work :/

I tried in my main *appdelegate.m and then in a another "page1.m"

I've used the below in the appdelegate.m

navigator.rootViewController.navigationController.view.backgroundColor = [UIColor redColor];
navigator.rootViewController.navigationController.navigationBar.backgroundColor = [UIColor redColor]; 
navigator.rootViewController.navigationItem.titleView.backgroundColor = [UIColor redColor];
navigator.rootViewController.navigationController.navigationBar.barStyle = UIStatusBarStyleBlackOpaque;
navigator.rootViewController.navigationController.topViewController.navigationController.navigationBar.barStyle = UIStatusBarStyleBlackOpaque;
navigator.rootViewController.navigationController.navigationBar.tintColor = [UIColor blackColor];
navigator.rootViewController.navigationController.navigationBar.translucent = YES;

I've used the below in the page1.m

self.statusBarStyle = UIStatusBarStyleBlackOpaque; // This works! but the below doesnt
self.navigationBarStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.backgroundColor = [UIColor redColor]; 
self.navigationItem.titleView.backgroundColor = [UIColor redColor];
self.navigationController.navigationBar.barStyle = UIStatusBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBar.translucent = YES;

What am i doing wrong?

Thanks

EDIT

Also tried the following and still did not work

self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationBarStyle = UIBarStyleBlackOpaque;

and

navigator.rootViewController.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
navigator.rootViewController.navigationController.topViewController.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

/EDIT2

Debugging did not give me my results, in my .m file, this is how its called

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    self.title = @"MyTitle";
NSLog(self.navigationController.navigationBar.topItem.title);//DIDNT WORK
NSLog(self.navigationItem.title);//Worked

Solution

  • self.navigationController.navigationBar.barStyle = UIStatusBarStyleBlackOpaque;
    

    should be:

    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
    

    //EDIT: for debugging purposes you can log all

    *.navigationBar.topItem.title
    

    and see if it prints out your current title. If not, its the wrong navigation controller.