4

I have 2 UIViewControllers. In the first UIViewController, say ViewController1 , I am keeping the UINavigationBar hidden. As my app's theme is black , so I need white UIStatusBar in iOS 7 so that it doesn't become invisible in black UINavigationBar. For getting white UIStatusBar I am using this method in iOS 7.

  1. set the UIViewControllerBasedStatusBarAppearance to YES in the plist
  2. in viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
  3. add the following method:

    -(UIStatusBarStyle)preferredStatusBarStyle{ 
      return UIStatusBarStyleLightContent; 
    } 
    

It works fine when I am in ViewController1 . But when I move to ViewController2 then if I set

self.navigationController.navigationBarHidden = NO 

in my viewDidLoad method. Then the above code for white UIStatusBar doesn't work. UIStatusBar becomes black and I can't see it because I am using the following codes to customize my UINavigationBar

self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
self.navigationController.navigationBar.translucent = NO; 

If I keep UINavigationBar hidden like ViewController1 then white UIStatusBar is visible again. But when UINavigationBar is visible then status bar becomes black again. That's the problem.

Can anyone help me in this context , how can I get white status bar like my ViewController1 ? Thanks in advance.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
ayon
  • 2,180
  • 2
  • 17
  • 32

2 Answers2

6

Have you tried adding this to both view controllers

-(UIStatusBarStyle)preferredStatusBarStyle{ 
    return UIStatusBarStyleLightContent; 
}
anders
  • 4,168
  • 2
  • 23
  • 31
0

You are probably just missing the attribute needed on the plist: View controller-based status bar appearance to NO.

EDIT: Check @caglar comment on previous answer for a more comprehensive answer to what's needed in general.

alasker
  • 309
  • 5
  • 18