Reputation: 4994
Is it possible to change status bar text color on other than default white and black? For example to red?
My app is targeting to iOS10, so I support the newest iOS SDK.
Upvotes: 1
Views: 679
Reputation: 1617
As you can see you can change status bar background color using private framework. I have spend some time to investigate able to the change text color. This is possible with objective c runtime. But I thinks apple does not like this. You can modify your main.c to look like this
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import "AppDelegate.h"
id testMethod(id object, SEL selector, NSUInteger style)
{
return [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
}
int main(int argc, char * argv[]) {
@autoreleasepool {
BOOL result = class_replaceMethod(NSClassFromString(@"UIStatusBarForegroundStyleAttributes"), @selector(textColorForStyle:), testMethod, "@24@0:8q16");
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
When you run you will see some thing like this:
NOTE: I does not investigate possible to change others colors, but I think it's real.
Upvotes: 0
Reputation: 31
As per the apple documentation, there is no methods to change the colour of the status bar however you can add view on the top of the screen and set the background colour of that view.
Upvotes: 0
Reputation: 1978
Try like this!
func setStatusBarBackgroundColor(color: UIColor) {
guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }
statusBar.backgroundColor = color
}
Upvotes: 0
Reputation: 198
I'm afraid not. We have only 2 modes:
public enum UIStatusBarStyle : Int {
case `default` // Dark content, for use on light backgrounds
@available(iOS 7.0, *)
case lightContent // Light content, for use on dark backgrounds
}
You can find more info on How to change Status Bar text color in iOS 7
Upvotes: 1