SleepNot
SleepNot

Reputation: 3038

Hide UINavigationBar but still show Status Bar

How can I hide the navigation bar by not hiding the status bar in my app? When I try [self.navigationController.navigationBar setHidden:YES]; it also hides the status bar. I need to show the status bar like this:

enter image description here

I need to first hide a visible navigation bar, make the status bar still visible and I also have a view that I need to move below the status bar, but the view is being positioned like the navigation bar is still there when I set the frame's position to 0,0.

I setup my statusbar as:

[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Upvotes: 8

Views: 5142

Answers (3)

John
John

Reputation: 8548

In my case, the status bar text and symbols were not shown because they had the same color as the background (black). I solved the problem by changing the background color:

[self.navigationController.navigationBar.superview setBackgroundColor:UIColor.whiteColor];

Upvotes: 0

Weiyi
Weiyi

Reputation: 1933

If you want to hide navigation bar but show status bar, you should set Top Space to Top Layout Guide as 0 instead of -44. and then

Hide navigation bar in viewWillAppear instead of viewDidLoad: [self.navigationController setNavigationBarHidden:YES animated:YES]

I start to set top space as -44, then call method [[UIApplication sharedApplication] setStatusBarHidden:NO], it doesn't work.

Upvotes: 0

Rose
Rose

Reputation: 437

Add this to your code where you want to hide the navigation bar

[self.navigationController.navigationBar setHidden:YES];

Upvotes: 1

Related Questions