Skip to content

Instantly share code, notes, and snippets.

@richkolasa
Created March 9, 2022 21:53
Show Gist options
  • Save richkolasa/b0751e21b12a6da74d973f500bf8fecc to your computer and use it in GitHub Desktop.
Save richkolasa/b0751e21b12a6da74d973f500bf8fecc to your computer and use it in GitHub Desktop.
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let referenceSize = UIFont.preferredFont(forTextStyle: .body,
compatibleWith: .init(preferredContentSizeCategory: .medium))
let newSize = UIFont.preferredFont(forTextStyle: .body)
let percentIncrease = (newSize.pointSize / referenceSize.pointSize) * 100
let js = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='\(Int(percentIncrease))%'"
webView.evaluateJavaScript(js) { _, error in
if let error = error {
print(error.localizedDescription)
} else {
print("success!")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment