Skip to content

Instantly share code, notes, and snippets.

@coryalder
Last active June 16, 2017 21:14
Show Gist options
  • Save coryalder/6d1596606f36ac994193 to your computer and use it in GitHub Desktop.
Save coryalder/6d1596606f36ac994193 to your computer and use it in GitHub Desktop.
class Dummy: NSObject {
@objc func barStyle() -> UIStatusBarStyle {
return .LightContent
}
func swizzle() {
guard let safariClass = NSClassFromString("SFSafariViewController") else {
print("can't swizzle, iOS 8")
return
}
let replacementMethod: Method = class_getInstanceMethod(object_getClass(self), "barStyle")
let swizzledMethod = class_getInstanceMethod(safariClass, "preferredStatusBarStyle")
method_exchangeImplementations(replacementMethod, swizzledMethod)
}
}
// Elsewhere (i.e. applicationDidFinishLaunching) I call Dummy().swizzle() to run this code.
@coryalder
Copy link
Author

This works around not being able to change SFSafariViewController's status bar color on an app that is deploying to iOS 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment