I have a Navigation proje开发者_StackOverflow社区ct 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:
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".
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.
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?
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.
navigationBar.barStyle = UIBarStyleBlackTranslucent;
(docs)
Full answer...
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
MyView *myView=[[MyView alloc]initWithNibName:@"myView" bundle:[NSBundle mainBundle]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myView];
[nav.navigationBar setBarStyle:UIBarStyleBlackOpaque];
Swift 3:
self.navigationController?.navigationBar.barStyle = UIBarStyle.blackTranslucent
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
In storyboard choose Translucent Black Navigation Bar
for Top Bar
To change the bar style to black-translucent (documentation)
navigationController?.navigationBar.barStyle = .black
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.tintColor = #colorLiteral(red: 1, green: 0.99997437, blue: 0.9999912977, alpha: 1)
精彩评论