doorman doorman - 1 year ago 114
iOS Question

Change statusbar text color programmatically inside the same view controller

I am using UIScrollView on iOS 9 with two pages and for the first page I want the statusbar text to be black and the second page white. So when I slide to the second page I want the statusbar color to turn white and black if I slide to the first page.

I have tried setting the
UIViewControllerBasedStatusBarAppearance to false in the plist file
and then programmatically calling:

UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackTranslucent;

But without luck, the statusbar text appears white and it stays white even when calling UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackTranslucent;

Any idea how to manually change the statusbar text color within the same view controller?

Answer Source

If you're using a Navigation Controller for your view controllers, try changing the property:


"Default" should be black and "LightContent" should be white. I believe the Black options are deprecated.

Otherwise, you could opt for View Controller based Status Bar Style in your Info.plist and use the preferredStatusBarStyle property as mentioned here.

In your ViewDidLoad method, do SetNeedsStatusBarAppearanceUpdate();

Add the following method:

 public override UIStatusBarStyle PreferredStatusBarStyle()
        return UIStatusBarStyle.LightContent; //Or Default/Black/etc.

Note: Using UIApplication.SharedApplication to change the status bar style has been deprecated in iOS 9. Use the above methods instead. Hope this helped. Cheers!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download