Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make navigation top bar style to same like "Black Navigation Bar" programmatically?

Tags:

iphone

I have a Navigation project which has only a TableView. By default, I could see the navigation bar there when running the application. I want to change the navigation bar style to same like if we see in I.B there is one called "Top Bar" which has "Black Navigation Bar" style (Which shows Black navigation top bar but some kind of Gray shade will be there). I want the same in my navigation bar now, not any other color or style. How do I fix it?

Note:

  1. I used "self.navigationController.navigationBar.barStyle = UIBarStyleBlack;", but it shows the navigation bar in utter black color. I don't want that, I want some kind of Gray shade in black, similar to "Top Bar" which has "Black Navigation Bar".

  2. I tried some tint color addition to the above, like "self.navigationController.navigationBar.tintColor = [UIColor grayColor];" but I observe the same utter black shows in navigation bar.

  3. I tried "navigationBar.barStyle = UIBarStyleBlackTranslucent;" but it doesn't fit and show with status bar properly. Instead it overlaps (hidden) half black with status bar and half black shows outside.

Could someone teach me?

like image 910
Getsy Avatar asked Apr 29 '10 21:04

Getsy


4 Answers

As UIBarStyleBlackTranslucent is deprecated in iOS 3.0,
it is better to use those two lines:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;  // optional
self.navigationController.navigationBar.translucent = YES;

This also allows you to use a different color than black.

like image 100
Gonen Avatar answered Nov 15 '22 07:11

Gonen


navigationBar.barStyle = UIBarStyleBlackTranslucent;

(docs)

like image 40
cobbal Avatar answered Nov 15 '22 08:11

cobbal


Full answer...

self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
like image 29
MGM Avatar answered Nov 15 '22 07:11

MGM


MyView *myView=[[MyView alloc]initWithNibName:@"myView" bundle:[NSBundle mainBundle]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myView];
[nav.navigationBar setBarStyle:UIBarStyleBlackOpaque];
like image 44
kenny varguez Avatar answered Nov 15 '22 06:11

kenny varguez