Nanfeng

Notes on software development, code, and curious ideas

Showing the iOS Status Bar in a Cocos Creator App

First, distinguish between these two iOS interface elements:

  1. Status bar: the strip that displays the time, battery level, and signal strength.
  2. Navigation bar: the common iOS UINavigationBar that contains a back button and title.

This article concerns the first one. A Cocos Creator export hides the status bar by default. Our game uses portrait orientation and the product requirements called for the status bar to be visible.

Update the view controller

Find the following two methods in the view controller and replace them with this code. If they do not exist, add them:

1
2
3
4
5
6
7
8
- (BOOL)prefersStatusBarHidden {
return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDarkContent; // Use on a light background.
// return UIStatusBarStyleLightContent; // Use on a dark background.
}

Check Info.plist

Make sure the status bar has not been disabled globally:

1
2
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

The recommended value is true, which lets the view controller decide whether the status bar is visible.

If the file contains:

1
2
<key>UIStatusBarHidden</key>
<true/>

Remove it or change it to:

1
2
<key>UIStatusBarHidden</key>
<false/>

After completing these steps, clear the build cache, rebuild the project, and run it again.

+