Pregunta

Note: I don't want to change the status bar color or text color to white or black. I know how to do that.

I want to change status bar text color to green.

Black

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

White

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

However I would like to know can I set some other color? Really I want this because all my app design goes ugly with white and black ;(

I know this is not possible, but still asking here as someone might know if there is way.

Now, if there is no way, what I am planning is to create custom view and put all what I see in status bar to my view as below, but black to green color.

enter image description here

Is there any way where I can gather all the information of status bar?

I will manage to refresh the view based on notification, but I want to find the way where we can gather all contents of status bar.

And most important, is it allowed?


What I wanted is as below.

enter image description here

¿Fue útil?

Solución

From the link provided by MidhunMP, I used as below.

/// 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:[UIColor colorWithRed:235/255.0 green:116/255.0 blue:35/255.0 alpha:1.0]];
        return YES;
    } else {
        return NO;
    }
}

Reference


Apple approves any color as status bar color... Yayyyy.... Finally....

I have used above code in 2-3 apps and Apple has approved.

Just while updating app, mention in notes that you are using above code (paste the code in notes, which is very important. Let apple know the code we are using). As we show the code to apple, they know that though we are accessing private api, we are not harming anything. So based on my request, they approved 2 apps on the app store. Apps are BaitBite, Lovely Collectibles & Q8Rent

Otros consejos

To avoid the memory leak warning, you could replace this piece of code in Fahim Parkar's answer:

[statusBar performSelector:setForegroundColor_sel withObject:[UIColor colorWithRed:235/255.0 green:116/255.0 blue:35/255.0 alpha:1.0]];

with this code:

UIColor* color = [UIColor colorWithRed:235/255.0 green:116/255.0 blue:35/255.0 alpha:1.0];
NSInvocation* const invocation = [NSInvocation invocationWithMethodSignature:[[statusBar class] instanceMethodSignatureForSelector:setForegroundColor_sel]];
invocation.target = statusBar;
invocation.selector = setForegroundColor_sel;
[invocation setArgument:&color atIndex:2];
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    [[UIApplication sharedApplication] setStatusBarHidden:false];
    UIView *statusBar=[[UIApplication sharedApplication] valueForKey:@"statusBar"];
    statusBar.backgroundColor = [UIColor redColor];

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];



    return YES;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top