Search code examples
ioscolorsios7statusbar

Is it possible to change the status bar text (foreground) color to an arbitrary color (i.e. not black or white)?


Does anyone know how to change the status bar text color?

I want the text to be in the color orange.

I'm not talking about the regular black or white color

`UIStatusBarStyleLightContent`; or `UIStatusBarStyleBlackOpaque`; or whatever. 

Solution

  • There is no documented way to change the text color to orange. However, it is definitively possible, because I just tried it out and it worked.

    Disclaimer: this is all undocumented territorry... it will probably not be approved when you submit it to the app store. however, you may be lucky...

    In iOS 7 you can do this:

    /// sets the status bar text color. returns YES on success.
    /// currently, this only
    /// works in iOS 7. It uses undocumented, inofficial APIs.
    BOOL setStatusBarColor(UIColor *color)
    {
        id statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
        id statusBar = [statusBarWindow valueForKey:@"statusBar"];
    
        SEL setForegroundColor_sel = NSSelectorFromString(@"setForegroundColor:");
        if([statusBar respondsToSelector:setForegroundColor_sel]) {
            // iOS 7+
            [statusBar performSelector:setForegroundColor_sel withObject:color];
            return YES;
        } else {
            return NO;
        }
    }
    

    in iOS5 and iOS6 it may be possible too, but I haven't tried, because it is much more work. However I have found a method of interest (available in iOS 5 and iOS 6). Class UIStatusBarItemView has an instance method called -textColorForStyle: (which takes an integer and returns an object). You may be able to monkey-patch it to return any color you like.