Skip to content

Instantly share code, notes, and snippets.

@scottjacksonx
Last active December 24, 2015 13:59
Show Gist options
  • Save scottjacksonx/6809283 to your computer and use it in GitHub Desktop.
Save scottjacksonx/6809283 to your computer and use it in GitHub Desktop.
This is a category on UIApplication that (as of iOS 7) lets you set the status bar foreground color (which is used as the color for things like the system time, signal strength indicators, and "alarm set" icon — everything in the status bar, except the battery indicator). I'm pretty sure it would pass App Store validation, but hopefully a review…
@implementation UIApplication (StatusBarForegroundColor)
- (void)setStatusBarForegroundColor:(UIColor *)foregroundColor {
SEL statusBarSelector = NSSelectorFromString(@"statusBar");
if ([self respondsToSelector:statusBarSelector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
id statusBar = [[UIApplication sharedApplication] performSelector:statusBarSelector
withObject:nil];
/*
Q: "What if the status bar is green or whatever? Don't you need
to check for a double-height status bar?"
A: Thanks for your question. Nope. iOS takes care of it. Set
the status bar's foreground color in your app and that's the
color it will be in your app. If the system changes the status
bar foreground color (e.g. making it white when making the status
bar double-height with a green background), it will be restored
to your color when iOS gets rid of the double-height status bar.
*/
SEL colorSelector = NSSelectorFromString(@"setForegroundColor:");
if ([statusBar respondsToSelector:colorSelector]) {
[statusBar performSelector:colorSelector withObject:foregroundColor];
}
#pragma clang diagnostic pop
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment