1

I am little bit confused about the status bar behaviour

I don't need transparent status bar I need it fixed and black colour. Same like iOS6

I tried a lot, what I get it, its showing black colour only when I launch the app first time, when I rotate the device to landscape and again make to portrait then it takes the navigation bar colour.

What I am doing wrong.

Can any one please guide me.

This is what I am getting

enter image description here

This is how I want

enter image description here

Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
Sagar
  • 1,286
  • 3
  • 19
  • 34
  • 2
    you can not do that. if you want to do same then you have to add view at same frame with (0,0,width,20) with background black colour. and set `View controller-based status bar appearance = NO` and `[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];` – ChintaN -Maddy- Ramani Nov 06 '14 at 09:28

2 Answers2

1

You cad do a hack to set status bar color, app wouldnt be rejected by Apple, but no guarantee that Apple wouldnt change this behaviour in next iOS versions.

- (void)setStatusBarColor:(UIColor *)color {
id statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"_statusBarWindow"];
NSString *statusBarWindowClassString = NSStringFromClass([statusBarWindow class]);

if ([statusBarWindowClassString isEqualToString:@"UIStatusBarWindow"]) {
    NSArray *statusBarWindowSubviews = [statusBarWindow subviews];

    for (UIView *statusBarWindowSubview in statusBarWindowSubviews) {
        NSString *statusBarWindowSubviewClassString = NSStringFromClass([statusBarWindowSubview class]);

        if ([statusBarWindowSubviewClassString isEqualToString:@"UIStatusBar"]) {
            [statusBarWindowSubview setBackgroundColor:color];
        }
    }
}
}
Ivan Golub
  • 89
  • 8
0

Here's a solution for iOS8, Swift, Xcode 6.3.

Add a background color:

var statusBarBackground = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 30))
statusBarBackground.backgroundColor = UIColor.blackColor()
statusBarBackground.tag = 13

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window!.rootViewController!.view.addSubview(statusBarBackground)
appDelegate.window!.rootViewController!.view.bringSubviewToFront(navigationController!.navigationBar)

Remove the background color:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
for sv in appDelegate.window!.rootViewController!.view.subviews {
    if sv.tag == 13 {
        sv.removeFromSuperview()
    }
}

Why didn't I just add statusBarBackground to the viewController's view? Because I needed this for the UIDocumentInteractionController Preview view, which, as it stands now, does not allow for any customization.

Why did I make statusBarBackground 30 high, thus forcing me to do a bringSubviewToFront for the navigationBar? Because my navigationbar has rounded corners (with mask layers, so not images), thus showing the view behind the navigation bar (which I want to be the same color as the statusbar background.

Still to figure out: If you tap the preview the nav bar moves up, but (of course) the statusVarBackground remains. No delegates that tell me the preview was tapped. If you have any idea, leave it in the comments.

guido
  • 2,792
  • 1
  • 21
  • 40