Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFSafariViewController status bar style

My app's statusbar style is UIStatusBarStyleLightContent and it's set in my rootViewController as preferredStatusBarStyle.

Now I have a problem that when opening SFSafariViewController from within my app, it has inherited statusbar style that is light and invisible on the white background of SFSafariViewController.

Is there a way to set statusbar style for SFSafariViewController?

P.S. I tried to subclass SFSafariViewController and override this method but it doesn't help.

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

Update:

[[UIApplication sharedApplication] setStatusBarStyle:] does the trick, but this method is deprecated in iOS 9.

like image 316
Alexander Tkachenko Avatar asked Oct 16 '15 14:10

Alexander Tkachenko


1 Answers

You don't have to subclass SFSafariViewController at all.

Just set modalPresentationCapturesStatusBarAppearance = true on your instance of SFSafariViewController and it will handle the rest on its own.

This works because its own default preferredStatusBarStyle is, you guessed it, .default. The view hierarchy is still relying on the presenting view controller for status bar appearance, so by setting modalPresentationCapturesStatusBarAppearance to true, it will be the receiver asked for status bar appearance.

TL;DR

safariViewController.modalPresentationCapturesStatusBarAppearance = true

(This behavior is overridden, doesn't work, when UIViewControllerBasedStatusBarAppearance is set to NO in your Info.plist)

like image 81
Clay Ellis Avatar answered Sep 28 '22 08:09

Clay Ellis