Skip to content

Instantly share code, notes, and snippets.

@michaelpeternell
Last active July 15, 2020 17:58
Show Gist options
  • Save michaelpeternell/27229b3fe9ab31ac4b34 to your computer and use it in GitHub Desktop.
Save michaelpeternell/27229b3fe9ab31ac4b34 to your computer and use it in GitHub Desktop.
Change the text color of the status bar on iPhone and iPad (works for iOS 7 - iOS 12)
/// 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;
}
}
@michaelpeternell
Copy link
Author

Disclaimer: please note that including this code into your app will probably prevent it from being approved by the app store. Don't say I didn't warn you!

@michaelpeternell
Copy link
Author

this no longer works with iOS 13 :-(
In iOS 13, the status bar is rendered by a system process and we therefore cannot "customize" it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment