1

When ill try to change the text-color of me StatusBar in iOS, there is always a delay for maybe 1-2 seconds. So it starts with black, and after that delay its getting white, as i want to.

All these changes are in my ViewController, in ViewDidLoad.

Ill use a custom view to get an specific color:

    let statusBarHeight = CGFloat(20)
    let colorBGView = UIView(frame: CGRectMake(0, -statusBarHeight, self.view.bounds.width, statusBarHeight))
    colorBGView.backgroundColor = UIColor.customDarkerGrey()
    self.navigationController?.navigationBar.addSubview(colorBGView)

And set the barStyle to Black (to get the white color font when using an UINavigationController)

    self.navigationController?.navigationBar.barStyle = UIBarStyle.Black

Set the Value for:

 View controller-based status bar appearance

In the plist.info to "YES"

But there is still a "lag" - so everything is white, but it takes up to 2 seconds. Any ideas?

Ill found not an answer question, because this is only about coloring, not for the problem with the delay:

preferredStatusBarStyle isn't called

Edit:

Ok, after creating a new Project with 2 ViewControllers and a NavigationController ill found out, that the "Delay" is normal, when you try to change the Color from ViewController to ViewController. It seems, that the function:

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
}

Is called with a little delay - and nothing happens when ill add:

self.setNeedsStatusBarAppearanceUpdate()

So in my case ill changed it globally on the NavigationController, and (because its loaded with my App) you do not recognize the "delay".

Maybe this is helpful for someone else.

Community
  • 1
  • 1
derdida
  • 14,784
  • 16
  • 90
  • 139
  • Could you please create a minimal example? – Sulthan Dec 23 '15 at 22:59
  • Make the call to `setNeedsStatusBarAppearanceUpdate` in `viewWillAppear:` – par Dec 24 '15 at 00:06
  • At the moment i dont see any differences (ill had in in ViewDidLoad) – derdida Dec 24 '15 at 00:09
  • Is this happening in the simulator only? Maybe you have slow animations (cmd-T) turned on in the simulator? – par Dec 24 '15 at 00:17
  • No there are no slow animations active. But at the moment only tried it in simulator. Ill already changed my code to change the color when the App gets loaded - so you are unable to recognize the delay. But if you want to simulate the behavior, just create a short project in Xcode and try to change the color on the second ViewController, and you will see that there is a short delay when the View is already loaded. – derdida Dec 24 '15 at 00:20
  • But thanks for your answers! Always nice when someone helps me to find out the little stupid behaviors of Xcode ;) – derdida Dec 24 '15 at 00:23

1 Answers1

0

Try to set color for status bar in AppDelegate in method didFinishLaunchinOptions. As your status bar color is set to other color by default and then you are setting it to new color in your controller, its creating delay.

And also

Set the Value for:

View controller-based status bar appearance

In the plist.info to "NO"

Krishna Kumar
  • 1,652
  • 9
  • 17
  • @derdida Did it helped you? – Krishna Kumar Dec 23 '15 at 23:08
  • How should ill set the color to white in my AppDelegate? There is no NavigationController there? And the preferredStatusBarStyle() method is only available on an ViewController. – derdida Dec 23 '15 at 23:38
  • And the StatusBar Color is fine, the problem is my Font Color. There is that delay. – derdida Dec 23 '15 at 23:39
  • @derdida Thats what I explained you.. if you will try to change appearance of status bar in some viewController when some default is already loaded then it creates delay.. – Krishna Kumar Dec 24 '15 at 10:42
  • You are unable to set the Color in the AppDelegate - the new (iOS9) method works only on ViewControllers. So you have to set it on your RootViewController/NavigationControlller, not in the AppDelegate. – derdida Dec 24 '15 at 10:45
  • You can set to navigationController/RootViewController in AppDelegate if you are creating it programmatically.. Although the idea was to set it first when app loads.. – Krishna Kumar Dec 24 '15 at 10:47