3

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
user370507
  • 477
  • 2
  • 12
  • 20

3 Answers3

4
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.

  • and the same in your AppDelegate ;) –  Jan 01 '11 at 19:21
  • Tried this, Still didn't work :(, edited top post to reflect this. Thanks for the help though – user370507 Jan 01 '11 at 19:24
  • even for self.navigationBarStyle ? –  Jan 01 '11 at 19:28
  • Yes, I've added what i've got at the top to reflect this. Maybe im doing something wrong still – user370507 Jan 01 '11 at 19:29
  • you can test every combination that could be possible even if the navigation bar is named differently. but it should be the topItem of a navigationBar, not the topItem of the controller or subitem –  Jan 01 '11 at 19:40
  • Your Right, Its not giving me my title when self.title gives me my title but the others dont! NSLog(self.navigationController.navigationBar.topItem.title);//Doesnt Give title NSLog(self.navigationItem.title);//Gives Title Maybe this helps? This is how its Done - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { self.title = @"MyTltle"; – user370507 Jan 01 '11 at 20:17
  • If you have a nib File then you can connect your navigationBar and then access this class variable –  Jan 01 '11 at 20:50
  • No Nib file, do not use the IB :/, is there a way to find out what the navigationbar is called on three20's framework? – user370507 Jan 02 '11 at 12:11
  • yes sure, I don't use the framework but as far as I know you have the full source code, so you have to open the source file you using and find out how it's named, sorry that I cannot say more, but I don't use it :D –  Jan 02 '11 at 13:04
0

This may be what your looking for... (make sure you change the tint color):

CGFloat version = [[[UIDevice currentDevice] systemVersion] floatValue];
//NSLog(@"version %f", version);
if (version <= 6.1) {
    //NSLog(@"setting navbar style to black");
    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackOpaque];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
}
manimaul
  • 322
  • 3
  • 5
0

UIStatusBarStyleBlackOpaque is a constant to style the status bar, which is the black or grey thing on the top of your screen, showing time, reception, battery charge etc.

You change it using

[[UIApplication sharedApplication] setStatusBarStyle:...]

as for changing a navigation bar, try the things you listed one by one, and make sure to do it not too early, i.e. not before the view controller has been loaded and initialized.

A good place for these things is in your view controllers -(void)viewDidLoad

mvds
  • 45,755
  • 8
  • 102
  • 111
  • Thanks, I the statusbar changes, bit the navigation bar doesnt change. I'm 100% sure i've loaded it as the last thing (even after it sets the title for the nav bar) and still doesnt work – user370507 Jan 01 '11 at 19:22