是否可以将状态栏文本(前景)颜色更改为任意颜色(即不是黑色或白色)?

use*_*981 2 colors statusbar ios ios7

有谁知道如何更改状态栏文本颜色?

我希望文本颜色为橙色.

我不是在谈论常规的黑色或白色

`UIStatusBarStyleLightContent`; or `UIStatusBarStyleBlackOpaque`; or whatever. 
Run Code Online (Sandbox Code Playgroud)

Mic*_*ael 8

没有记录的方法文本颜色更改为橙色.但是,它确实是可能的,因为我只是尝试了它并且它起作用了.

免责声明:这是所有未记录的领土......当您将其提交到应用程序商店时,它可能不会被批准.但是,你可能很幸运......

在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;
    }
}
Run Code Online (Sandbox Code Playgroud)

在iOS5和iOS6中也有可能,但我还没有尝试过,因为它的工作要多得多.但是我找到了一种感兴趣的方法(在iOS 5和iOS 6中可用).Class UIStatusBarItemView有一个名为的实例方法-textColorForStyle:(它接受一个整数并返回一个对象).您可能可以对其进行修补以返回您喜欢的任何颜色.


归档时间:

查看次数:

1754 次

最近记录:

7 年,1 月 前