Search code examples
iosobjective-cstatusbar

Status bar style light content if deployment target is below iOS 7?


In the app I am working on I unfortunately have to use iOS 6 as my deployment target (iOS 7 being my base SDK). Is there any way I can have the UIStatusBar style Light Content? Even though it would only work for the iOS 7 users.


Solution

  • This is the enum for UIStatusBarStyle:

    typedef NS_ENUM(NSInteger, UIStatusBarStyle) {
        UIStatusBarStyleDefault                                     = 0, // Dark content, for use on light backgrounds
        UIStatusBarStyleLightContent     NS_ENUM_AVAILABLE_IOS(7_0) = 1, // Light content, for use on dark backgrounds
        UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 1,
        UIStatusBarStyleBlackOpaque      NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 2,
    };
    

    We can see from this that UIStatusBarStyleLightContent is the same value as UIStatusBarStyleBlackTranslucent, so those will be the respective behaviors on iOS 6 and 7 if either of those are used.

    If you wanted to, you could use code to detect the iOS version and choose a different value between the two, in case you wanted the light content style on iOS 7, but black opaque or default on iOS 6.

    Also, there's now a property that you add to the Info.plist called UIViewControllerBasedStatusBarAppearance that will make it so it will change the style based on the preference of the UIViewController using the - (UIStatusBarStyle)preferredStatusBarStyle method. So you just override that method in your UIViewController subclass with the style you want in that specific place.