Skip to content

Instantly share code, notes, and snippets.

@ham118
Last active May 5, 2023 08:07
Show Gist options
  • Save ham118/a9eb7f0178c688638708cde56c2f4699 to your computer and use it in GitHub Desktop.
Save ham118/a9eb7f0178c688638708cde56c2f4699 to your computer and use it in GitHub Desktop.
EvaluatingJavaScript : This is gist to change font size and avoid text copy functionality from entire html in UIWebView | Swift 5
//This is code to change font size and avoid text copy functionality from entire html in UIWebView
//"textSize" : this is integer variable which you want to set font size
func webViewDidFinishLoad(_ webView: UIWebView) {
if (webView.stringByEvaluatingJavaScript(from: "document.readyState") == "complete") {
//Avoid to detect touch gesture for disable user selection
webView.stringByEvaluatingJavaScript(from: "document.documentElement.style.webkitUserSelect='none';")
webView.stringByEvaluatingJavaScript(from: "document.documentElement.style.webkitTouchCallout='none';")
//Set font size
let jsString = "document.getElementsByTagName('body')[0].style.fontSize='\(textSize)px'"
webView.stringByEvaluatingJavaScript(from: jsString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment