状态栏自定义文本颜色

时间:2017-04-27 11:05:41

标签: ios swift

是否可以更改状态栏文本颜色而不是默认的白色和黑色?例如红色?

我的应用程序定位到iOS10,因此我支持最新的iOS SDK。

4 个答案:

答案 0 :(得分:1)

我不敢。我们只有两种模式:

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
}

您可以在How to change Status Bar text color in iOS 7

上找到更多信息

答案 1 :(得分:0)

试试这个!

 func setStatusBarBackgroundColor(color: UIColor) {

        guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }

        statusBar.backgroundColor = color
    }

答案 2 :(得分:0)

根据Apple文档,没有方法可以更改状态栏的颜色,但是您可以在屏幕顶部添加视图并设置该视图的背景颜色。

答案 3 :(得分:0)

如您所见,您可以使用私有框架更改状态栏背景颜色。我花了一些时间来研究改变文本的颜色。这可以通过目标c运行时实现。但我认为苹果不喜欢这个。你可以修改main.c看起来像这样

#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]));
  }
}

当你跑步时,你会看到这样的事情:

注意:我不会调查改变其他颜色的可能性,但我认为这是真的。

相关问题