Skip to content

Instantly share code, notes, and snippets.

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