颜色更改为任意颜色

颜色更改为任意颜色

本文介绍了是否可以将状态栏文本(前景)颜色更改为任意颜色(即非黑色或白色)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

Does anyone know how to change the status bar text color?

我希望文本为橙色。

我不是在谈论普通的黑色或白色

I'm not talking about the regular black or white color

`UIStatusBarStyleLightContent`; or `UIStatusBarStyleBlackOpaque`; or whatever.


推荐答案

没有有记载的方式 >将 text 颜色更改为橙​​色。但是,这绝对有可能,因为我只是尝试了一下就可以了。

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...

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

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

在iOS5和iOS6中也可能我没有尝试过,因为它需要做很多工作。但是,我发现了一种有趣的方法(在iOS 5和iOS 6中可用)。类 UIStatusBarItemView 有一个名为 -textColorForStyle:的实例方法(它使用一个整数并返回一个对象)。您也许可以用猴子修补它来返回您喜欢的任何颜色。

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.

这篇关于是否可以将状态栏文本(前景)颜色更改为任意颜色(即非黑色或白色)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:19