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

StackOverflow https://stackoverflow.com/questions/23383508

  •  12-07-2023
  •  | 
  •  

Question

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. 
Was it helpful?

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.

OTHER TIPS

You can't change it to orange.

Black and white are currently the only available status bar content / texr colors.

The Apple UI guidelines mentioned that Don’t create a custom status bar.

The default color of the content / text in the status bar is black and this can cause the status bar to become unreadable if the content behind the status bar is dark.

In order to remedy this issue you can set the UIStatusBarStyle of your application and/or views. UIStatusBarStyleLightContent changes the color of the content in the status bar to white; alternately, UIStatusBarStyleDefault sets the color of the status bar content to black.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top