12

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: Storyboard Simulator

Community
  • 1
  • 1
FrankZp
  • 2,022
  • 3
  • 28
  • 41

3 Answers3

4

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

Lupurus
  • 3,618
  • 2
  • 29
  • 59
  • imo the feature status bar tinting is not cleanly implemented by Apple. Your solution is a workaround. The clean solution should be that the app checks for the status bar tint on each view controller - not only on the first view controller. – FrankZp Feb 18 '13 at 16:05
2

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 https://i.stack.imgur.com/n9ubK.png)

der_michael
  • 3,151
  • 1
  • 24
  • 43
  • Yes this new feature picks the color of the top navigation bar to tint the status bar. But the requirement here is, that the first View Controller has no navigation bar. In iOS 5 this was possible with the code above. But in iOS 6 the status bar is unchangeable! – FrankZp Sep 30 '12 at 11:01
  • 1
    _On the TableViewController the status bar should have Default Style (grey in iOS 5, Blue Tinted due to navigation bar in iOS 6)._ This assumption is wrong. – der_michael Sep 30 '12 at 17:42
  • The code shown above sets the status bar on the TableViewController to Default Style. This works in iOS5 - not in iOS6 (status bar stays black - see Simulator screenshot). – FrankZp Oct 01 '12 at 09:23
0

You don't have to set the style for the navigation bar to your tableviewcontroller.

Try this approach. 1. Add navigation controller to the main view. 2. Set its property hidden to yes. 3. When you display tableviewcontroller, set the navigation bar property hidden to No

Navigation Controller -> bar hidden= yes -> MainView -> bar hidden=no -> TableView

NNikN
  • 3,720
  • 6
  • 44
  • 86
  • The problem is that the TableViewController is displayed modally. Therefore MainViewController and TableViewController cannot be embedded in the same Navigation Controller (see Storyboard Screenshots). When two Navigation Controller are used (one for MainView and one for TableView) the problem discribed above stays the same... – FrankZp Oct 01 '12 at 09:19