iOS7 - 是否可以更改状态栏颜色? [英] iOS7 - Is it possible to change status bar color?

查看:177
本文介绍了iOS7 - 是否可以更改状态栏颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何更改状态栏文字颜色?我想要橙色。



我不是说常规的黑色或白色
UIStatusBarStyleLightContent UIStatusBarStyleBlackOpaque ;管他呢。

解决方案

没有文档化的方式可将橙子。



免责声明:这是所有未记录的领土,它可能不会被批准,当你将其提交到应用商店。



在iOS 7中,您可以执行此操作:

  ///设置状态栏文本颜色。成功时返回YES。 
///目前,这只有
///在iOS 7中工作。它使用未记录,非正式的API。
BOOL setStatusBarColor(UIColor * color)
{
id statusBarWindow = [[UIApplication sharedApplication] valueForKey:@statusBarWindow];
id statusBar = [statusBarWindow valueForKey:@statusBar];

SEL setForegroundColor_sel = NSSelectorFromString(@setForegroundColor:);
if([statusBar respondingToSelector:setForegroundColor_sel]){
// iOS 7+
[statusBar performSelector:setForegroundColor_sel withObject:color];
return YES;
} else {
return NO;在iOS5和iOS6中,也可以是
}
}

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

注意:我只是在我的github页面上发布代码


Does anyone know how to change the status bar text color? I want it orange.

I'm not talking about the regular black or white color UIStatusBarStyleLightContent; or UIStatusBarStyleBlackOpaque; or whatever.

解决方案

There is no documented way to change the text color to orange. However, it is definitively possible, because I just tried it out and it worked.

Disclaimer: this is all undocumented territorry... it will probably not be approved when you submit it to the app store. however, you may be lucky...

In iOS 7 you can do this:

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

in iOS5 and iOS6 it may be possible too, but I haven't tried, because it is much more work. However I have found a method of interest (available in iOS 5 and iOS 6). Class UIStatusBarItemView has an instance method called -textColorForStyle: (which takes an integer and returns an object). You may be able to monkey-patch it to return any color you like. I don't know if it will work, though. You may need to enumerate through all status bar items and call -setNeedsDisplay manually on each, in order to have the color change be visible immediately, but who knows...

Note: I just published the code at my github page too.

这篇关于iOS7 - 是否可以更改状态栏颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆