Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The correct way to set a light status bar text color in iOS 7 based on different ViewControllers

I need to let a specific ViewController embedded in an UINavigationController to have light status bar text color (but other ViewControllers to behave differently). I am aware of at least 3 methods, none of which however work in my case.

  1. How to change Status Bar text color in iOS 7, the method is primarily:

    • Set the UIViewControllerBasedStatusBarAppearance to YES in the plist
    • In viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
    • Add the following method:

      - (UIStatusBarStyle)preferredStatusBarStyle{ 
            return UIStatusBarStyleLightContent; 
        }
      

    Running on iOS 7.0.3, this method does not work for me, since even after I have implemented all 3 steps correctly, preferredStatusBarStyle is never called.

  2. UIStatusBarStyle PreferredStatusBarStyle does not work on iOS 7, the method is primarily:

    Setting your navigationBar’s barStyle to UIBarStyleBlackTranslucent will give white status bar text (ie. UIStatusBarStyleLightContent), and UIBarStyleDefault will give black status bar text (ie. UIStatusBarStyleDefault).

    This method works fair and square on iPhone, but not on iPad.

  3. Setting the UIViewControllerBasedStatusBarAppearance to NO in the plist, and use

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    

    This clearly doesn't apply in this case, since I need to only specify different status bar colors for two of the ViewControllers.

Thanks for all help!

like image 983
lwxted Avatar asked Jan 12 '14 05:01

lwxted


People also ask

How do I change the font color on my status bar?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.

Can we change status bar color in iOS?

You can change the status bar colour just with a single line of code. Just updated the markdown for iOS 13 and below.

How do I change the color of a status bar in Swift?

Open your info. plist and set UIViewControllerBasedStatusBarAppearance to false . In the first function in AppDelegate. swift , which contains didFinishLaunchingWithOptions , set the color you want.


1 Answers

For people having this problem with a UINavigationController I can recommend creating a custom UINavigationController and implementing the preferredStatusBarStyle on it like this:

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return [self.topViewController preferredStatusBarStyle];
}

That way the statusbar style will be that of the top view controller. Now you can implement the view controller's preferredStatusBarStyle anyway you like.

like image 73
Groot Avatar answered Oct 13 '22 05:10

Groot