1
votes

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.

1
Could you please create a minimal example?Sulthan
Make the call to setNeedsStatusBarAppearanceUpdate in viewWillAppear:par
At the moment i dont see any differences (ill had in in ViewDidLoad)derdida
Is this happening in the simulator only? Maybe you have slow animations (cmd-T) turned on in the simulator?par
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

1 Answers

0
votes

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"