Skip to content

Instantly share code, notes, and snippets.

@zentrope
Last active December 23, 2018 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentrope/7b4ea586256804cceb585ce19f781c20 to your computer and use it in GitHub Desktop.
Save zentrope/7b4ea586256804cceb585ce19f781c20 to your computer and use it in GitHub Desktop.
Set dark/light for web content
private func setMode(_ isDark: Bool) {
let mode = isDark ? "add" : "remove"
let script = "document.body.classList.\(mode)(\"dark\");"
webView.evaluateJavaScript(script) { result, error in
if let err = error {
os_log("%{public}s", log: logger, type: .error, "js error: \(err).")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment