Raymond Moay Raymond Moay - 5 months ago 19
Swift Question

Updating status bar appearance by toggling between lightContent and default using UIbutton

I am making an app which allows users to change the theme, eg. changing the background colour. Assuming I have a button, when click, toggles the change in background colour.

Eg. in code:

@IBAction func floodLightAction(sender: AnyObject) {

previousFloodlightOption = loadFloodlightOption()

if previousFloodlightOption {

print("OFF")

saveFloodlightOption(false)

// configure theme for themeViewController:

UIApplication.sharedApplication().statusBarStyle = .Default

setNeedsStatusBarAppearanceUpdate()

configureFloodlight(false)


} else {

print("ONN")

saveFloodlightOption(true)

// configure theme for themeViewController:

UIApplication.sharedApplication().statusBarStyle = .LightContent

setNeedsStatusBarAppearanceUpdate()

configureFloodlight(true)

}


However, setNeedsStatusBarAppearanceUpdate() does not seem to update the status bar style when the button is pressed. I have a few custom functions which are explained below.

My custom save func:

saveFloodlightOption(bool: Bool)



  • This saves a boolean value using NSUserDefaults.



My theme configuration func:

configureFloodLight(bool: Bool)



  • This just change objects' colour in the view controller based on the theme picked.



I hope I gave enough information, thanks!

Answer

Have you set View Controller Based Status bar appearance to false in your info.plist?

View Controller Based status bar appearance

Comments