I have a view controller with a Light Status Bar Style, and then a user can press a button which modally presents a Game Center Leaderboard. However, I want the modal view controller to have a .Default
style when the parent view controller has a .LightContent
style. Is this possible to do? Can the modal view controller have a different style than the parent view controller? If so, how would I achieve this?

- 1,374
- 17
- 39
-
Definitely possible. In each view controller, are you overriding `- preferedStatusBarStyle:`? – ajfigueroa Feb 06 '16 at 23:50
-
@ajfigueroa Actually since I am presenting a Game Center leaderboard I don't have a view controller for the Game Center Leaderboard. – Harish Feb 06 '16 at 23:54
4 Answers
I've had the same problem. My solution was to override: GKGameCenterViewController
class
Then I've followed answer here: I have added
preferredStatusBarStyle()
method into my override view controller and set UIViewControllerBasedStatusBarAppearance
to NO
in the .plist file.

- 1
- 1

- 941
- 1
- 8
- 19
-
Just one question though for some reason when I use your solution the whole apps status bar appearance turns black. How do I have some white status bar colors? Is there a way to do that? – Harish Feb 28 '16 at 00:55
-
I have also put `preferredStatusBarStyle()` into my `BaseViewController` which I use as parrent class to all of my View controllers. – Zuzana Paulis Feb 28 '16 at 01:04
-
I have done that, but it is not working when I set the value to NO in the plist, and it works when the value is set to YES in the plist. – Harish Feb 28 '16 at 01:06
-
-
No, I don't have my views embedded in a Navigation View. The views have white status bars if the view controller based status bar appearance is set to yes, but then the Game Center View status bar is white instead of black – Harish Feb 28 '16 at 14:23
Well I think I figured out a good solution to my question. Basically when presenting modally, you have a completionHandler
. In the completionHandler
put these lines of code when you are presenting the modal view:
self.setStatusBarStyle(.Default)
self.setNeedsStatusBarAppearanceUpdate()
When you are dismissing the modal view:
self.setStatusBarStyle(.LightContent)
self.setNeedsStatusBarAppearanceUpdate()
Make sure not to implement the preferredStatusBarStyle in your View Controller. That method was throwing me off and if you implement the preferredStatusBarStyle method it will override the setStatusBarStyle method and this trick won't work. Basically DO NOT implement preferredStatusBarStyle.

- 1,374
- 17
- 39
This solved it for me:
modalViewController.modalPresentationStyle = .overCurrentContext

- 717
- 1
- 9
- 15
The following answer is based on @Harish's solution. In your specific UIViewController
(or your own base class) add:
var statusBarStyle: UIStatusBarStyle = .lightContent
override var preferredStatusBarStyle: UIStatusBarStyle {
return statusBarStyle
}
And call:
self.statusBarStyle = .default // or .lightContent
self.setNeedsStatusBarAppearanceUpdate()
Whenever you want to change status bar style.

- 7,009
- 1
- 58
- 44