iOS7 – 是否可以更改状态栏的颜色?

有谁知道如何改变状态栏的文字颜色? 我想要它橙色。

我不是在谈论常规的黑色或白色的颜色UIStatusBarStyleLightContent ; 或者UIStatusBarStyleBlackOpaque ; pipe他呢。

没有logging的方法来将文本颜色更改为橙​​色。 然而,这是完全可能的,因为我只是试了一下,它的工作。

免责声明:这是所有没有logging的territorry …它可能不会批准,当你提交到应用程序商店。 然而,你可能是幸运的

在iOS 7中,你可以这样做:

 /// 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; } } 

在iOS5和iOS6中可能也是可以的,但我还没有尝试过,因为它是更多的工作。 不过,我发现了一种感兴趣的方法(可在iOS 5和iOS 6中使用)。 UIStatusBarItemView类有一个名为-textColorForStyle:的实例方法-textColorForStyle:它接受一个整数并返回一个对象)。 你可以猴子补丁来恢复你喜欢的任何颜色。 但是,我不知道它是否会起作用。 您可能需要枚举所有状态栏项目,并手动调用-setNeedsDisplay手动设置,以便使颜色更改立即可见,但谁知道…

注:我刚刚在我的github页面上发布了代码 。

你不能把它改成橙色。

黑色白色是目前唯一可用的状态栏内容/ texr颜色。

Apple UI准则提到, 不要创build自定义状态栏

状态栏中的内容/文本的默认颜色为黑色 ,如果状态栏后面的内容很暗,可能导致状态栏变得不可读。

为了解决这个问题,你可以设置你的应用程序和/或视图的UIStatusBarStyleUIStatusBarStyleLightContent将状态栏中内容的颜色更改为白色; 或者, UIStatusBarStyleDefault将状态栏内容的颜色UIStatusBarStyleDefault为黑色。

在这里输入图像说明

尝试使用以下代码在didFinishLaunchingWithOptions方法中

 self.window.backgroundColor = [UIColor colorWithRed:0.89f green:0.11f blue:0.17f alpha:1]; // set color as you want [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; 

如果你正在谈论状态栏的文字颜色,那么这个网站上有这么多的问题:

状态栏文字颜色iOS 7
如何更改iOS 7中的状态栏文字颜色
更改白色iOS 7 / Xcode 5的状态栏文字颜色