Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Statusbar on Modal Views iOS 6

Tags:

statusbar

ios6

I have the following constellation:

Main View (Custom UIViewController, no navigationcontroller or navigation bar), containing a button which segues modally to a second Table view controller, which is embedded in a Navigation Controller:

MainView -> Navigation Controller -> TableView

On the MainView the status bar is Black (no changes with iOS 6 - even when Status Bar is set to Default) On the TableViewController the status bar should have Default Style (grey in iOS 5, Blue Tinted due to navigation bar in iOS 6).

In iOS 5 this was easy by the following lines of code in TableViewController:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarStyle:)]) {
   [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}

Running this under iOS 6 noting happens. How can I do this? I tried all possible Status Bar settings under project summary and in the plist (like described here: https://stackoverflow.com/a/12468689/1685971)

Also, in Storyboard everything looks fine. Running the app in simulator or on the device it looks different: StoryboardSimulator

like image 442
FrankZp Avatar asked Sep 20 '12 12:09

FrankZp


2 Answers

try this "hack": You have to add a navigation bar to your first view controller. Then you have two possibilities.

1) Set the alpha value of the navigation bar to 0

or

2) Set the y-position of the bar to -43px (look here: http://moduscreate.com/tinting-your-status-bar-in-ios6-and-phonegap/)

EDIT:

To get the right colors you have to set the tintColor of the invisible UINavigationBar. So by default set it black. In your button action you have to set the tintColor to your navigationController.navigationBar.tintColor. At the action of your close button you need to set it back to [UIColor blackColor].

like image 157
Lupurus Avatar answered Oct 27 '22 20:10

Lupurus


The first view controller must have a navigation controller/bar for the feature to work. The status bar does not change color throughout your app (in iOS6) but adapts to the navigationbar color of you starting view. If your starting view does not contain a navigationbar, the status bar does not adapt color.! (See http://i.stack.imgur.com/n9ubK.png)

like image 28
der_michael Avatar answered Oct 27 '22 21:10

der_michael