Created
March 9, 2022 21:53
-
-
Save richkolasa/b0751e21b12a6da74d973f500bf8fecc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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