I'd like to change the color of status bar from white to black by press button, programmatically only in a single-ViewController
This is the code:
- (UIStatusBarStyle)preferredStatusBarStyle {
NSLog(@"PreferredStatusBarStyle");
if(nav_bar.alpha==1)
{
NSLog(@"->UIStatusBarStyleBlackOpaque");
return UIStatusBarStyleBlackOpaque;
}
else
{
NSLog(@"->UIStatusBarStyleLightContent");
return UIStatusBarStyleLightContent;
}}
then When I press a button action is:
[self setNeedsStatusBarAppearanceUpdate];
But this doesn't work!
When I press the button log write the correct status according to navbar.alpha, but statusbar text color remain UIStatusBarStyleBlackOpaque like when view appear.
what you need to do, is to call the -setStatusBarStyle:animated: method thru the shared application, like this
you can use it without the animated parameter as well. keep in mind that UIStatusBarStyleBlackOpaque is deprecated in iOS 7, documentation says you wanna use UIStatusBarStyleLightContent instead
edit: sorry, if u wanna use preferredStatusBarStyle, take a look at this preferredStatusBarStyle isn't called